刷新页面后,控制台的js代码继续执行

在各种限时,秒杀活动中,有个自动循环的点击的工具是很重要的。

为了方便起见,我们把Js代码放在浏览器的控制台执行,但是刷新页面后,js代码就清空了,也就无法执行。

可以用js代码实现一个不受页面刷新影响不断执行的代码,如下:

1. 必要的知识

prompt() 弹出对话框,获取用户输入的文本
setTimeout(,) 延迟执行函数
write() 可向指定对象写入html代码或者js代码
with() 设定代码的作用域

2.大致框架

var timeout = prompt("设置刷新时间");
current = location.href;
if(timeout > 0)
{
  setTimeout(
'reload()', 1000 * timeout); } else {
  location.replace(current); }
function reload() {
  
setTimeout('reload()', 1000 * timeout);   var frame = '<frameset cols=\'*\'>\n<frame src=\'' + current + '\' /></frameset>';
  
with(document)
  {
// 引用document对象,调用write方法写入框架,打开新窗口
    
write(frame);
  
    //此处输入代执行的代码
    
// 关闭上面的窗口
    void(close());
  }; }

猜你喜欢

转载自www.cnblogs.com/wujiecong/p/11549738.html