html刷新js重载入代码方法汇总

JavaScript常用页面刷新重载的方法:

<a href="javascript:location.reload();">点击重新载入页面</a>
<a href="javascript:history.go(0);">点击重新载入页面</a>
<a href="javascript:location=location;">点击重新载入页面</a>
<a href="javascript:location=location.href;">点击重新载入页面</a>
<a href="javascript:location.replace(location);">点击重新载入页面</a>
<a href="javascript:location.replace(location.href);">点击重新载入页面</a>
<a href="javascript:location.assign(location);">点击重新载入页面</a>
<a href="javascript:location.assign(location.href);">点击重新载入页面</a>
<!--// 以下只支持ie -->
<a href="javascript:document.URL=location.href;">点击重新载入页面</a>
<a href="javascript:navigate(location);">点击重新载入页面</a>
<a href="javascript:document.execCommand('Refresh');">点击重新载入页面</a>
<!--// 以上只支持ie -->

html链接重新载入方法

<!--// 以下不支持ie -->
<a href="">点击重新载入页面</a>
<!--// 以上不支持ie -->
<a href="页面本身">点击重新载入页面</a>

自动刷新页面的方法

<meta http-equiv="refresh" content="20">  //代码放在head中,每隔20秒钟刷新一次

<meta http-equiv="refresh" content="20;url=http://www.haorooms.com">  //20秒之后页面跳转到haorooms中,通常运用到404页面

点击的链接都在新窗口打开:<meta http-equiv="windows-target" content="_top"/>

//js自动刷新
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次

返回上一页和下一页的方法

history.go(-1) //返回上一页(括号中写-2代表返回上两页)

history.back() //返回上一页

window.history.forward()  //返回下一页

setTimeout("window.location.href='evaluate.php?E_id="+data.id+"'",2000)  //两秒后跳转url链接

<input type=button value=刷新 οnclick="history.go(0)">

<input type=button value=刷新 οnclick="location.reload()">

<input type=button value=刷新 οnclick="location=location">

<input type=button value=刷新 οnclick="location.assign(location)">

<input type=button value=刷新 οnclick="document.execCommand('Refresh')">

<input type=button value=刷新 οnclick="window.navigate(location)">

<input type=button value=刷新 οnclick="location.replace(location)">

<input type=button value=刷新 οnclick="window.open('自身的文件','_self')">

<input type=button value=刷新 οnclick=document.all.WebBrowser.ExecWB(22,1)>

<a href="javascript:void(0)" οnclick="history.go(0)"></a>

<a href="javascript:void(0)" οnclick="location=location"></a>

<a href="javascript:history.back(); ">刷新后返回上一个url地址,即不变地址</a>  

<a href="javascript:history.go(-1);location.reload();">后退不变位置刷新</a> 

<a href="javascript:window.history.back();">后退不变位置</a> 

<a href="javascript:history.back();">不变URL后退</a>  //子窗口刷新父窗口
<a href="javascript:opener.location.reload();">刷新</a> 

延时刷新
setTimeout("window.location.reload()",5000); 
延时刷新
javascript:setTimeout(function(){window.location.reload()},3000);
<body οnlοad="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新

location.reload()方法用于重新加载当前文档。
setTimeout("location.reload();",1000);在1秒以后调用location.reload()函数,只调用一次。
setInterval("location.reload();",1000);每隔1秒调用location.reload()函数,循环调用多次。
点击刷新一次
<div style="cursor:pointer;text-align:center;" class="load-box"><a style="font-size:36px;font-weight:bold;" href="javascript:location.reload()"><br><br>点击这儿刷新一下<br>快~快~快~戳我两下~</a></div>

延时5秒后自动跳转<script type="text/javascript">document.οncοntextmenu=function(e){return false;};document.onselectstart=function(e){return false;};window.setTimeout("window.location='userlt.php'",5000);</script>

为了让页面进行刷新,可以使用location.reload()方法,但是这种方法会让页面一直不断的刷新,这是因为当页面加载完成以后,我们让它刷新一次,那么浏览器就会重新向服务器请求数据,界面会重新加载,然后,加载完成又调用了location.reload()方法,这样就陷入了死循环,一直处于请求然后刷新的状态。为了解决这样的问题,我们使用下面这种方式:

$(document).ready(function () {

     if(location.href.indexOf("#reloaded")==-1){
        location.href=location.href "#reloaded";
        location.reload();
    }
 })
#在这后面可以加入程序的其他代码即可,利用以上方法,在每次进入这个页面的时候,都会绕过浏览器缓存,重新向服务器获取数据。

用iframe、弹出子页面刷新父页面iframe
<script language=JavaScript> parent.location.reload(); </script> 
弹出子页面
<script language=JavaScript> window.opener.location.reload(); </script> 
子窗口刷新父窗口
<script language=JavaScript> self.opener.location.reload(); </script> 
刷新以open()方法打开的窗口
<script language=JavaScript> window.opener.location.href=window.opener.location.href; </script> 
刷新以winodw.showModelDialog()方法打开的窗口
<script language="javascript"> window.parent.dialogArguments.document.execCommand('Refresh'); </script> 

关闭当前页面并自动刷新父页面的代码:

window.location.href="javascript:window.opener=self.opener.location.reload();window.open('','_self');window.close()";

非模态刷新父页面:window.opener.location.reload(); 
模态刷新父页面:window.dialogArguments.location.reload(); 
 

用js控制页面只刷新一次,只刷新一次


==========第一种:改变URL

function reurl(){
        url = location.href;
        var times = url.split("?t=");
        if(times[1] != 1){
          url += "?t=1";
          self.location.replace(url);
        }
      }
      window.onload = function() {
        setTimeout("reurl()", 100);//0.1秒后刷新
      }


==========第二种:不改变URL刷新一次页面


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
(function()
{
    var value = readCookie('shuaxinyemian');
    if(value == null)
    {
        var date = new Date();
        date.setTime(date.getTime()+(3600000));
        var expires = "; expires="+date.toGMTString();
        document.cookie = "shuaxinyemian=1"+expires+"; path=/";
        window.location.reload();
    }
    else
    {
        var date = new Date();
        date.setTime(date.getTime()-(3600000));
        var expires = "; expires="+date.toGMTString();
        document.cookie = "shuaxinyemian="+expires+"; path=/";
    }
})();
 

两秒钟后自动刷新代码:<meta http-equiv="refresh" content="2;url=要刷新地址">

后退刷新代码:<a href="javascript:history.back();">
立即刷新:<input type=button value="刷新1" οnclick="window.location.reload()">
延时3秒执行链接跳转:<a href=index.php>返回</a>'; header("Refresh:3;url=index.php");

//指定9秒循环刷新本页面一次
<Script language="javascript">function myrefresh(){window.location.reload()}setTimeout("myrefresh()",9000);</Script>

1秒后只刷新页面一次
<script type="text/javascript">function fresh() {if(location.href.indexOf("?reload=true") < 0) {location.href += "?reload=true";} } setTimeout("fresh()",1000);</script>


只刷新一次
<body οnlοad="if (location.href.indexOf('reload')==-1) {location.replace(location.href)}">

5秒之后刷新1次 五秒之后刷新一次
<script type="text/javascript">function fresh() {if(location.href.indexOf("?reload=true") < 0) {location.href += "?reload=true";} } setTimeout("fresh()",5000);</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

轶软工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值