浏览器刷新页面

约定不等于承诺〃 2023-10-06 09:04 155阅读 0赞

浏览器刷新的四种方法:

方法一:head中添加meta标签

每5秒刷新一次,5秒后跳转到指定链接

  1. <meta http-equiv="refresh" content="5" />
  2. <meta http-equiv="refresh" content="5;url=https://www.baidu.com/" />

方法二:刷新网页

  1. window.location.reload();//刷新当前页
  2. window.location.replace("https://www.baidu.com/");//指定刷新位置
  3. window.location.href='https://www.baidu.com/';
  4. document.execCommand('Refresh');

返回并刷新页面:

  1. location.replace(document.referrer);
  2. document.referrer //前一个页面的URL

方法三:利用定时任务

  1. function domRefresh() {
  2. window.location.reload();
  3. }
  4. setTimeout('domRefresh();', 1000); //单位为毫秒*/

方法四:按钮版本

  1. <p><input type="button" onclick="javascript:location.reload();" value="刷新当前页面"></p>
  2. <a title="刷新" class="btn btn-success radius r" style="line-height: 1.6em; margin-top: 3px;" href="javascript:location.replace(location.href);">刷新</a>

发表评论

表情:
评论列表 (有 0 条评论,155人围观)

还没有评论,来说两句吧...

相关阅读

    相关 浏览器页面刷新

    浏览器页面跳转刷新行为会触发窗口跳转,并向服务器发送请求。如form表单提交、a标签超链接跳转,window.location.href等行文都会触发窗口的刷新,而窗口刷新后根

    相关 页面局部刷新

    场景:页面A使用第三方插件C,如果页面刷新,C会重新初始化并且无法记录之前的信息。现在希望页面的主要功能区B刷新,但是C的信息不要丢失。 解决方案:B采用iframe方式...