JS Refresh Page Method Daquan

Source: Internet
Author: User

This article introduces several methods of using JS to refresh the current page, including reload method, replace method, automatic Refresh method, etc. If you need a friend, refer to it.

How do I refresh the current page? With JS you will be omnipotent.

The 1,reload method, which forces the browser to refresh the current page.
Syntax: Location.reload ([Bforceget])
Parameters: Bforceget, optional parameter, default is False, the current page is taken from the client cache. True, the latest page from the server is taken as a GET, equivalent to the client clicking F5 ("Refresh")

The 2,replace method, which replaces the currently cached item in history (client) by specifying a URL, so you cannot access the URL that has been replaced by "forward" and "back" after using the Replace method.
Syntax: Location.replace (URL)
Usually used: Location.reload () or history.go (0) to do.
This method is similar to the client Point F5 Refresh page, so when the page method= "POST", a "page expiration" prompt appears.
Because of the security protection mechanism of the session.
When the Location.reload () method is called, the ASPX page is already present in the server's memory, so it must be IsPostback.
If there is such an application: the page needs to be reloaded, that is, the desired page can be re-created on the server and the expectation is not IsPostback.
Here, Location.replace () can complete this task. The Replace page is regenerated on the server each time.
Code: Location.replace (LOCATION.HREF);

To return and refresh the page:

Location.replace (Document.referrer);
Document.referrer//URL of previous page

Do not use History.go (-1), or history.back (), to go back and refresh the page, neither of these methods refreshes the page.
Report:

JavaScript refreshes the page in several ways:

1,history.go (023,location=45,document.execcommand (' Refresh '6  78,document. Url=location.href

Ways to automatically refresh pages:
 
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.jb51.net" >

Where 20 means jump to http://www.jb51.net page after 20 seconds
3, page automatically refresh JS version

<script language= "JavaScript" >function  Myrefresh () {   window.location.reload ();} SetTimeout (// specify 1 seconds to refresh once </script>

4,JS script statements that refresh the framework

// Refresh the page containing the frame with    <script language=javascript>   parent.location.reload (); </script>// child window Refresh parent window <script language=javascript>     Self.opener.location.reload (); </script> (or <a href= "javascript:opener.location.reload ()" > Refresh </a>   )//  Refresh the page of another frame   with <script language=javascript>   parent. Another FrameID.location.reload (); </script>

If you want to refresh when you close the window or if you want to open it, call the following statement in <body>.

<body onload= "Opener.location.reload ()" > Windows Refresh <body onunload= "opener.location.reload ()" >  Refresh <script language= "JavaScript" >window.opener.document.location.reload ()on Close </script>

First, let's look at a simple example:

The following three pages were named Frame.html, top.html, bottom.html as an example to specify how to do.
Frame.html consists of two pages (top.html) under (bottom.html), the code is as follows:

Now assume that top.html (that is, the page above) has seven buttons to implement the bottom.html (that is, the following page) refresh, you can use the following seven kinds of statements, which is good to see.
The code for the Top.html page is as follows:

Here is the bottom.html page source code, in order to prove that the page below is indeed refreshed, in the loading page pop up a dialog box.

Inch

Explain:

123451 history.go (023 location=4  5 Document.execcommand (' Refresh '67

second, automatically refresh the page
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.jb51.net" >
Where 20 means jump to http://www.jb51.net page after 20 seconds
3. Page automatically refresh JS version

function Myrefresh () {window.location.reload ();} setTimeout (//

Third, JS refresh the framework script statement
1. How to refresh the page containing the frame

<script language=javascript>

2. child window Refreshes parent window

<script language=javascript>self.opener.location.reload ();

3. How to refresh the page of another frame (above example to illustrate)

Statement 1. Window.parent.frames[1].location.reload (); Statement 2. Window.parent.frames.bottom.location.reload (); Statement 3. window.parent.frames["Bottom"].location.reload (); Statement 4. Window.parent.frames.item (1). Location.reload (); Statement 5. Window.parent.frames.item (' bottom '). Location.reload (); Statement 6. Window.parent.bottom.location.reload (); Statement 7. window.parent[

4. 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 ()" >
Refresh when opening windows
<body onunload= "Opener.location.reload ()" >
Refresh when off

<script language= "JavaScript" >window.opener.document.location.reload ()

Learn a little bit more everyday code less knock a little bit 

JS Refresh Page Method Daquan

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.