【问题标题】:How do you close all webpages with a certain title? [closed]你如何关闭所有具有特定标题的网页? [关闭]
【发布时间】:2015-09-17 15:11:03
【问题描述】:

我的[网站]:http://www.zombrom.com/experiments/popular.html 有一个自动重新加载器,每次重新加载时它都会重新打开页面我想知道如何一次关闭所有这些网站这是我当前的代码,它不会打开还有更多网站:

setInterval(function() {
  location.reload();
  window.open("http://www.zombrom.com/experiments/popular.html");
}, 1000);
<center><b>Ready!</b>
</center>

【问题讨论】:

  • 小巨人又怎么了?
  • 我不是在问为什么这段代码不起作用!!!

标签: javascript html reload


【解决方案1】:

你可以使用window.close()

window.close

var openWindows =  [], newWindow;
setInterval(function() {
  /* Will not work with location.realod() */
  //location.reload();
  //push reference to the opened windows into an array
  newWindow = window.open("http://www.zombrom.com/experiments/popular.html");
  openWindows.push(newWindow);
}, 1000);

/* call this function when you want to close all the windows that you have opened*/
function closeAllOpenWindows(){
   openWindows.forEach(function(openWindow){
      openWindow.close();
     }
   );
}

【讨论】:

  • 这实际上是如何工作的? location.reload(); 重新加载页面,所有变量都被重新初始化……还有reload() 就像一个return,之后就什么都不会执行了。
  • 抱歉,我没有注意到location.reload()。它不适用于location.reload()
猜你喜欢
  • 2013-08-13
  • 2021-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-21
  • 1970-01-01
  • 2019-09-02
  • 1970-01-01
相关资源
最近更新 更多