使用JavaScript重新加载HTML页面一次 [英] Reload an HTML page just once using JavaScript

查看:113
本文介绍了使用JavaScript重新加载HTML页面一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何只能重新加载一次HTML基础网页?我在body标签中使用 history.go(0); 与函数 onLoad ,但我只想运行它一次。请记住,我正在使用 iframe ,因此无法使用以下类型的代码:

< script language =JavaScript><! -  
function MyReload()
{
window.location.reload();
}
// - >< / script>

< Body onLoad =MyReload()>

以上代码不适用于我



但下面的代码工作正常,但问题是我需要它加载一次

 < BODY BGCOLOR =#FFFFFF background =../ images / Index_04.jpgonLoad =history.go(0)> 

注意:当用户点击主页链接时,我使用2个iframe加载iframe中的页面希望用当前的iframe页面重新加载整个页面。

解决方案

您可以使用 querystring 在页面结尾处(例如?r),并在重定向之前检查它,就好像它存在一样,重定向已经完成。如果(window.location.href.substr(-2)!==?r){
window.location = window.location.href +?r; $ p>
}

免责声明:我同意其他人的看法,您可能有更好的解决方案 - 永远不需要刷新'一次'。



使用说明

您的页面底部,位于< / body> 的上方,您应该放置这个:

 < script type =text / javascript> 
if(window.location.href.substr(-2)!==?r){
window.location = window.location.href +?r;
}
< / script>

就是这样。


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 not worked for me

but the below code is work good but the problem is that i need it to loads once

<BODY BGCOLOR=#FFFFFF background="../images/Index_04.jpg" onLoad="history.go(0)" >

note: I am using 2 iframes when user click on main page link a page loads in iframe than i want to reload the whole page with current iframe page.

解决方案

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'.

Explanation of use

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>

That's it.

这篇关于使用JavaScript重新加载HTML页面一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆