How do I refresh the current page? With JS you will be omnipotent.
1, the reload method, which forces the browser to refresh the current page.
Syntax: Location.reload ([Bforceget])
Parameters: bforceget, optional parameters, default tofalseTo fetch the current page from the client cache.true, the latest page from the server is taken as a GET, which is equivalent to the client clicking F5 ("Refresh")
2, the 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)
Commonly used: Location.reload () or History.go (0) to do.
This method is similar to the client Point F5 Refresh page, so the page method="Post"Occurs when the"Page Expires"The prompt.
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//the URL of the 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:
Copy the code code as follows:
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
Ways to automatically refresh pages:
1, the page automatically refreshes: Add the following code to the Copy the code code as follows:
<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 Copy the code code as follows:
<meta http-equiv="Refresh"Content="20;url=http://www.jb51.net">
Where 20 refers to 20 seconds after the jump to http://www.jb51.net Page
3, the page automatically refreshes the JS version
Copy the code code as follows:
<script language="JavaScript">
function Myrefresh ()
{
Window.location.reload ();
}
SetTimeout ('Myrefresh ()', +);//Specify 1 seconds to refresh one time
</script>
4, JS refreshes the framework's script statement
Copy the code code as follows:
//Refresh the page containing the frame with
<script language=javascript>
Parent.location.reload ();
</script>
//child window refreshes 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>.
Copy the code code as follows:
<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 ()
</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:
Copy the code code as follows:
<! DOCTYPE HTML Public"-//W3C//DTD HTML 4.0 transitional//en">
<HTML>
<HEAD>
<TITLE> Frame </TITLE>
</HEAD>
<frameset rows="50%,50%">
<frame Name=top src="top.html">
<frame Name=bottom src="bottom.html">
</frameset>
</HTML>
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:
Copy the code code as follows:
<! DOCTYPE HTML Public"-//W3C//DTD HTML 4.0 transitional//en">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<input Type=button value="Refresh 1"onclick="window.parent.frames[1].location.reload ()"><br>
<input Type=button value="Refresh 2"onclick="window.parent.frames.bottom.location.reload ()"><br>
<input Type=button value="Refresh 3"onclick="window.parent.frames[' Bottom '].location.reload ()"><br>
<input Type=button value="Refresh 4"onclick="Window.parent.frames.item (1). Location.reload ()"><br>
<input Type=button value="Refresh 5"onclick="window.parent.frames.item (' bottom '). Location.reload ()"><br>
<input Type=button value="Refresh 6"onclick="window.parent.bottom.location.reload ()"><br>
<input Type=button value="Refresh 7"onclick="window.parent[' Bottom '].location.reload ()"><br>
</BODY>
</HTML>
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.
Copy the code code as follows:
<! DOCTYPE HTML Public"-//W3C//DTD HTML 4.0 transitional//en">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<body onload="alert (' I've been loaded! ')">
isThe contentinchBottom.html.</BODY>
</HTML>
Explain:
Copy the code code as follows:
1The. window refers to the current page, for example it refers to the top.html page.
2The. Parent refers to the parent page of the current page, which is the frame page that contains it. For example, in this case, it refers to framedemo.html.
3. Frames is a Window object and is an array. Represents all the sub-pages within the framework.
4The. Item is a method. Returns the elements inside the array.
5If the sub-page is also a frame page, and there are other sub-pages, then some of the above methods may not work.
Report:
JavaScript refreshes the page in several ways:
1History.go (0)
2Location.reload ()
3Location=location
4Location.assign (location)
5Document.execcommand ('Refresh')
6Window.navigate (location)
7Location.replace (location)
8Document. Url=location.href
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 refers to 20 seconds after the jump to http://www.jb51.net Page
3. page auto-Refresh JS version
<script language="JavaScript">
function Myrefresh ()
{
Window.location.reload ();
}
SetTimeout ('Myrefresh ()', +);//Specify 1 seconds to refresh one time
</script>
Run code copy code save code [Ctrl + a full selection Note: If you need to introduce external JS need to refresh to execute]
Third, Java in the writing servler,action, and so on, to operate back to the page (such as talking about the window, after the completion of the operation, close the current page, refresh the parent page)
Copy the code code as follows:
1PrintWriter out= Response.getwriter ();
2 out. Write ("<script type=\ "text/javascript\" >");
3////child window refreshes the parent window
4 out. Write ("self.opener.location.reload ();");
5//Close Window
6 out. Write ("Window.opener=null;");
7 out. Write ("window.close ();");
8 out. Write ("</script>");
Iv. script statements for JS Refresh framework
1How to refresh the page that contains the frame
Copy the code code as follows:
<script language=javascript>
Parent.location.reload ();
</script>
2. child window Refreshes parent window
Copy the code code as follows:
<script language=javascript>
Self.opener.location.reload ();
</script>
3How to refresh the page of another frame (above example to illustrate)
Copy the code code as follows:
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['Bottom'].location.reload ();
4Call 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
Copy the code code as follows:
<script language="JavaScript">
Window.opener.document.location.reload ()
</script>
JS Refresh Page Method Daquan