We introduced the usage ofJavaScriptto 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) anddocument.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 thewindow object, set its location.href property , the location attribute is supported by every browser. For example:
top
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 backto 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 thearea
where 20 means to refresh the page every 20 seconds.
2. The page automatically jumps: add the following code to thearea
where 20 refers to jumping after 20 seconds Go to //m.sbmmt.com page
3. The page automatically refreshes the js version
JS refresh frame The script statement
//如何刷新包含该框架的页面用 //子窗口刷新父窗口 www.jbxue.com ( 或 刷新 ) //如何刷新另一个框架的页面用
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.
开窗时刷新 关闭时刷新
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:
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!