Several ways to refresh JavaScript pages

Source: Internet
Author: User

JavaScript Refresh page Several ways of refreshing pages

This section contains methods and examples of how JavaScript refreshes the current page.

Window.location.reload (), Window.history.go (0), and Document.execcommand ("Refresh"), these three methods are the fastest. There are obvious browser scroll bars appearing in the other.
JavaScript refreshes the page in several ways:  
1 history.go (0)
unless there is <%. %> such as the page code that needs to be interpreted on the server to generate, otherwise the data in the direct read cache
does not refresh
2 location.reload ()
to reconnect the servers to read the new page (although the page is the same)  
Refresh
3 Location=location
To navigate in JavaScript, not to call a method of the Window object, but to set its Location.href property, which is supported by every browser. For example:
<span onclick= "javascript:window.location.href= ' #top '" >TOP</SPAN>
back, forward
4 Location.assign (location)
Loads the new HTML document specified by the URL. The equivalent of a link to jump to the specified URL, the current page will be converted to new page content, you can click Back to return to the previous page.  
5 document.execcommand (' Refresh ')  
6 window.navigate (location)
MSDN says Window.navigate (sURL) method is for IE, not for FF, in HTML DOM Window object, the Window.navigate method is not listed at all.
7 location.replace (location)
does not back up, forward
replaces the current document by loading the document specified by the URL, this method replaces the current window page, and the previous two pages share a
window, So there's no back.
8 document that returns to the previous page. Url=location.href

JavaScript refreshes the page in several ways:
1 history.go (0)
2 Location.reload ()
3 location=location
4 Location.assign (location)
5 Document.execcommand (' Refresh ')
6 Window.navigate (location)
7 Location.replace (location)
8 document. Url=location.href

How to automatically refresh pages: JavaScript Auto-Refresh page method
1. Automatic page refresh: Add the following code to the <meta http-equiv= "Refresh" content= ">"
20 refers to a refresh of the page every 20 seconds.

2. Page Auto-jump: Add the following code to the <meta http-equiv= "Refresh" content= "20;url=http://www.jbxue.com" >
Where 20 means jump to http://www.jbxue.com page after 20 seconds

3. Page automatically refresh JS version

<script language= "JavaScript" >function Myrefresh () {window.location.reload ();} SetTimeout (' Myrefresh () ', 1000); Specify a 1-second refresh once </script>

JS Refresh Framework Script statement

How to refresh the page that contains the frame with <script language=javascript>parent.location.reload (); </script>//child window refreshes the parent window <script Language=javascript>self.opener.location.reload ();</script> www.jbxue.com (or <a href= "Javascript:o Pener.location.reload () "> Refresh </a>)//How to refresh the page of another frame with <script language=javascript> Parent. Another FrameID.location.reload ();</script>

Call the following statement in <body> if you want to refresh the window or refresh it when you want to open it.

<body onload= "Opener.location.reload ()" > Windows refresh <body onunload= "Opener.location.reload ()" > Off Refresh < Script language= "javascript" >window.opener.document.location.reload () </script>

Several ways to refresh JavaScript pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.