使用 JavaScript 重新加载 HTML 页面一次 [英] Reload an HTML page just once using JavaScript
问题描述
如何仅重新加载 HTML 基础网页一次?我在 body 标签中使用 history.go(0);
和函数 onLoad
但我只想运行它一次.请记住,我使用的是 iframe
,因此无法使用以下类型代码:
How can I reload an HTML base web page only once? I am using history.go(0);
with function onLoad
in body tag but i want to run it only once. Please keep in mind that I am using iframe
so this is not possible to to use the below types code:
<script language=" JavaScript" ><!--
function MyReload()
{
window.location.reload();
}
//--></script>
<Body onLoad=" MyReload()" >
上面的代码对我不起作用.
The above code did not work for me.
然而,下面的代码运行良好,但问题是我只需要加载一次:
However the code below is working well but the problem is that I need it to load only once:
<BODY BGCOLOR=#FFFFFF background="../images/Index_04.jpg" onLoad="history.go(0)" >
注意:当用户单击主页链接时,我使用了两个 iframe,一个页面在 iframe 中加载,然后我想用当前 iframe 页面重新加载整个页面.
Note: I am using two iframes when user click on main page link a page loads in iframe then I want to reload the whole page with current iframe page.
推荐答案
您可以在页面 url 的末尾使用 querystring
(例如 ?r),并在重定向之前检查它,如如果存在,则重定向已经完成.
You could use a querystring
at the end of the page url (e.g. ?r), and check for it before redirecting, as if it exists, the redirect is already done.
if(window.location.href.substr(-2) !== "?r") {
window.location = window.location.href + "?r";
}
免责声明:我同意其他人的看法,您可能有更好的解决方案 - 并且永远不需要只刷新一次".
Disclaimer: I agree with others that you probably have a better solution - and should never need to refresh 'just once'.
使用说明
在页面底部,就在 </body>
上方,您应该放置:-
At the bottom of your page, just above the </body>
you should put this:-
<script type="text/javascript">
if(window.location.href.substr(-2) !== "?r") {
window.location = window.location.href + "?r";
}
</script>
就是这样.
这篇关于使用 JavaScript 重新加载 HTML 页面一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!