Home  >  Article  >  Web Front-end  >  js refresh page location.reload() usage

js refresh page location.reload() usage

高洛峰
高洛峰Original
2016-12-17 15:45:082226browse

In JavaScript programming, location.reload is often used to refresh the page.

Example:

window.location.href=window.location.href; 
window.location.reload;

After testing, these two sentences can replace location.reload(true);
in some cases without a retry dialog box to achieve the refresh effect

How to refresh the page in js There are many kinds. There is a location.reload() function in js, which can achieve the function we want.
window.location.reload(true) //The browser re-requests resources from the server and does not include cache tags in the http request header.

Example 1, refresh the current page

<script> 
window.location.reload(); 
</script>

Example 2, JS implementation of refreshing iframe method
Use the name attribute of iframe to position

<input type="button" name="Button" value="Button" onclick="document.frames(&#39;ifrmname&#39;).location.reload()"> 
或 
<input type="button" name="Button" value="Button" onclick="document.all.ifrmname.document.location.reload()">

Example 3, first, define an iframe

<iframe method="post" id ="IFrameName" src="aa.htm" ></iframe>

aa.htm page content:

<input type ="button" value ="刷新" onclick ="aa()"/> 
function aa() { (php中文网 www.php.cn 编辑整理)
//parent.location.replace(parent.location.href);//服务器端重新创建页面 
parent.document.location.reload();//相当于F5 
//window.location.href(parent.location.href);//iframe内容重定向 
}

Note:
window.location.reload;
If you submit data during refresh, a dialog box will appear!

Solution:

window.location.href=window.location.href; 
window.location.reload;

Refresh the parent window:

window.opener.location.href=window.opener.location.href; 
window.opener.location.reload();


For more js refresh page location.reload() usage related articles, please pay attention to PHP Chinese website!


Statement:
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