在使用堡垒机的时候需要找别的同事要验证码,堡垒机5分钟不操作就自动掉线了,为了能一直在线,就想着能不能自动刷新页面,于是有了下面的代码,放到控制台执行就行,特别方便。
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);
}