美文网首页
JS刷新页面及页面跳转

JS刷新页面及页面跳转

作者: bryan_liu | 来源:发表于2020-10-28 11:59 被阅读0次
    返回上一页
    history.go(-1);
    history.back();
    window.history.forward();
    window.history.go();  参数可以是第几页 也可是访问过的url
    
    刷新页面
    history.go(0);
    location.reload();
    location = location;
    location.assign(location);
    document.execCommand('Refresh');
    window.navigate(location);
    location.replace(location);
    document.URL=location.href;
    
    自动刷新页面
    页面自动刷新,把如下代码加入<head>区域中,表示每隔20秒刷新一次页面:
    <meta http-equiv="refresh" content="20">
    页面自动跳转,把如下代码加入<head>区域中,表示20秒后自动跳转到https://www.baidu.com页面:
    <meta http-equiv="refresh" content="20;url=https://www.baidu.com">
    定时器实现自动刷新页面:
    <script language="JavaScript">
        function myrefresh(){
            window.location.reload();
        }
        setTimeout('myrefresh()',1000); //指定1秒刷新一次
    </script>
    
    关闭窗口或者打开窗口时刷新页面
    在<body>中调用以下语句:
    <body onload="opener.location.reload()"> 开窗时刷新
    <body onUnload="opener.location.reload()"> 关闭时刷新
    <script language="javascript">
        window.opener.document.location.reload()
    </script>
    

    相关文章

      网友评论

          本文标题:JS刷新页面及页面跳转

          本文链接:https://www.haomeiwen.com/subject/mvpqvktx.html