Home > Web Front-end > JS Tutorial > body text

Summary of methods for refreshing JS pages

黄舟
Release: 2017-11-16 14:16:51
Original
4419 people have browsed it

We introduced the usage of JavaScript to refresh the page location.reload(). In fact, there are many ways to refresh the page in JS, and this is just one of them. So today we Let me take you to learn a summary of the method of refreshing the page with JS!

window.location.reload(), window.history.go(0) and document.execCommand(''Refresh''), these three methods are the fastest of. Others have obvious browser scroll bars.
Several ways to refresh the page using Javascript:
1 history.go(0)
Unless there are pages such as <%..%> that need to be interpreted on the server side to be generated code, otherwise read the data in the cache directly
No refresh
2 location.reload()
You need to reconnect to the server to read the new page (although the page is the same)
Refresh
3 location=location
To navigate in javascript, instead of calling a method of the window object, set its location.href property , the location attribute is supported by every browser. For example:

<span onclick=”javascript:window.location.href=’#top’”>top</span>
Copy after login

Back and forward after execution
4 location.assign(location)
Load the new HTML document specified by the URL. It is equivalent to a link that jumps to the specified url. The current page will be converted to the new page content. You can click Back to return to the previous page.
5 document.execCommand('Refresh')
6 window.navigate(location)

The window.navigate(sURL) method mentioned by MSDN is for IE and does not apply to FF , in the HTML DOM Window Object, the window.navigate method is not listed at all.
7 location.replace(location)
No back or forward after execution
Replace the current document by loading the document specified by the URL. This method is to replace the current window page, the two before and after The pages share a
window, so there is no back to return to the previous page
8 document.URL=location.href

Javascript Several methods to refresh the page:
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

Method to automatically refresh the page: javascript automatically Detailed explanation of the method of refreshing the page
1. Automatically refresh the page: Add the following code to the area

<meta http-equiv="refresh" content="20">
Copy after login

where 20 means to refresh the page every 20 seconds.

2. The page automatically jumps: add the following code to the area

<meta http-equiv="refresh" content="20;url=http://www.php.cn">
Copy after login

where 20 refers to jumping after 20 seconds Go to http://www.php.cn page

3. The page automatically refreshes the js version

<script language="JavaScript">function myrefresh()
{
window.location.reload();
}
setTimeout(&#39;myrefresh()&#39;,1000); //指定1秒刷新一次</script>
Copy after login

JS refresh frame The script statement

//如何刷新包含该框架的页面用 
<script language=JavaScript>
parent.location.reload();
</script>

//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script> www.jbxue.com
( 或 <a href="javascript:opener.location.reload()">刷新</a> )

//如何刷新另一个框架的页面用 
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
Copy after login

If you want to refresh when the window is closed or you want to refresh when the window is opened, just call the following statement in .

<body onload="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新

<script language="javascript">
window.opener.document.location.reload()
</script>
Copy after login

Summary:

This article describes the method of refreshing the page in JavaScript through examples, which mainly explains the more commonly used ones. There are several methods, friends can choose the method that suits them according to their own needs!

related suggestion:

Usage of JavaScript refresh page location.reload()


JS refresh page sum! Various JS refresh page codes!


JS refresh page method collection

The above is the detailed content of Summary of methods for refreshing JS pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template