【JS】console定时刷新页面,不会因刷新而失效


 

代码

var timeout = prompt("Set timeout (Second):");
var count = 0;
var current = location.href;
if (timeout > 0) {
    setTimeout('reload()', 1000 * timeout);
} else {
    location.replace(current);
}

function reload() {
    count++;
    console.log('每(' + timeout + ')秒自动刷新,刷新次数:' + count);
    var fr4me = '<frameset cols=\'*\'>\n<frame src=\'' + current + '\'/>';
    fr4me += '</frameset>';
    with (document) {
        write(fr4me);
        void(close())
    }
    setTimeout('reload()', 1000 * timeout);
}

 

回车

 

 设置自动刷新时间,这里设置5秒

 

 

 

 

也可以在代码第一行直接设置自动刷新多少秒

 

参考文章:https://blog.csdn.net/jiang18238032891/article/details/103917553


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM