请问批量打开网址的JS怎么写?

waaoo 2020-04-21 12:01:25
每天固定要打开50个特定的网址(地址可能相同,也可以有所区别)

想使用html+js的方式,一次可以循环打开我录好的网址,请问这JS怎么写?

网上有一些批量打开网址的工具网站,不过都没法下载,在线用的话,每次用之前还要粘贴网址进去,所以想做成本地的,一个html文件搞定

感谢!感谢!


...全文
652 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
horizon_zpy 2020-04-21
  • 打赏
  • 举报
回复

<script>
arr=[
'http://baidu.com',
'http://bing.com'


]
for (i=0;i<arr.length;i++){
s=arr[i]; open_win(s);

}

function open_win(s) {
window.open(s);
}


</script>
horizon_zpy 2020-04-21
  • 打赏
  • 举报
回复

<script>
arr=[
'http://baidu.com',
'http://bing.com'


]
for (i=0;i<arr.length;i++){
s=arr[i]; open_win(s);

}

function open_win(s) {
window.open(s);
}


</script>
waaoo 2020-04-21
  • 打赏
  • 举报
回复
引用 6 楼 天际的海浪 的回复:
这个根本不用写代码,教你个方法: 在Chrome浏览器的书签栏中添加个文件夹,把要批量打开的网址都添加到这个文件夹里,之后右键点击这个文件夹,选择“打开全部(xx个)书签”
这个方法我知道,但我要的不是这样的,因为我要批量打开的网址有可能完全一样,默认情况下没法放很多个放在浏览器的文件夹中,同一个网址不能添加第2个
waaoo 2020-04-21
  • 打赏
  • 举报
回复
引用 8 楼 天际的海浪 的回复:
[quote=引用 5 楼 waaoo 的回复:] 谢谢,测试可用,符合我的要求,感谢感谢,但在DW中打开有个错误提示
你的DW版本太老了,es6箭头函数都不能识别?[/quote] CC2014,的确有点老了
天际的海浪 2020-04-21
  • 打赏
  • 举报
回复
引用 5 楼 waaoo 的回复:
谢谢,测试可用,符合我的要求,感谢感谢,但在DW中打开有个错误提示
你的DW版本太老了,es6箭头函数都不能识别?
天际的海浪 2020-04-21
  • 打赏
  • 举报
回复
或者按住Ctrl键+左键点击文件夹也可以
天际的海浪 2020-04-21
  • 打赏
  • 举报
回复
这个根本不用写代码,教你个方法: 在Chrome浏览器的书签栏中添加个文件夹,把要批量打开的网址都添加到这个文件夹里,之后右键点击这个文件夹,选择“打开全部(xx个)书签”
waaoo 2020-04-21
  • 打赏
  • 举报
回复
引用 4 楼 nian_cj 的回复:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>一键打开网站</title>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    html, body {
      height: 100%;
      font-size: 12px;
    }
    .textarea-box {
      padding: 20px;
    }
    .textarea-box #textarea {
      width: 100%;
    }
    .footer {
      text-align: center;
    }
    .footer button {
      display: inline-block;
      height: 30px;
      line-height: 30px;
      width: 100px;
    }
  </style>
</head>
<body>
  <div class="textarea-box">
    <textarea id="textarea" rows="10">
      https://element.eleme.cn/2.4/#/zh-CN/component/selecthttp://fanyi.youdao.com/https://www.baidu.com/
    </textarea>
  </div>
  <div class="footer">
    <button id="openBtn">
      打开网站
    </button>
    <button id="clearBtn">
      清空
    </button>
  </div>
  <script>
    document.body.onload = function() {
      var textareaDom = document.querySelector("#textarea"),
        openBtnDom = document.querySelector("#openBtn"),
        clearBtnDom = document.querySelector("#clearBtn");
      openBtnDom.onclick = function() {
        if (textareaDom) {
          fnOpenUrl(textareaDom.value || "");
        }
      }
      clearBtnDom.onclick = function() {
        if (textareaDom) {
          textareaDom.value = "";
        }
      }
      function fnOpenUrl(str) {
        if (str) {
          (str.split("http") || []).forEach(url => {
            url = url.replace(/\s/g, "");
            if (url) {
              url = url && "http" + url;
              if (/(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(url)) {
                window.open(url);
              } else {
                console.log("不是一个网址", url)
              }
            }
          });  
        }
      }

    }
  </script>
</body>
</html>
谢谢,测试可用,符合我的要求,感谢感谢,但在DW中打开有个错误提示
_念_ 2020-04-21
  • 打赏
  • 举报
回复
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>一键打开网站</title>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    html, body {
      height: 100%;
      font-size: 12px;
    }
    .textarea-box {
      padding: 20px;
    }
    .textarea-box #textarea {
      width: 100%;
    }
    .footer {
      text-align: center;
    }
    .footer button {
      display: inline-block;
      height: 30px;
      line-height: 30px;
      width: 100px;
    }
  </style>
</head>
<body>
  <div class="textarea-box">
    <textarea id="textarea" rows="10">
      https://element.eleme.cn/2.4/#/zh-CN/component/selecthttp://fanyi.youdao.com/https://www.baidu.com/
    </textarea>
  </div>
  <div class="footer">
    <button id="openBtn">
      打开网站
    </button>
    <button id="clearBtn">
      清空
    </button>
  </div>
  <script>
    document.body.onload = function() {
      var textareaDom = document.querySelector("#textarea"),
        openBtnDom = document.querySelector("#openBtn"),
        clearBtnDom = document.querySelector("#clearBtn");
      openBtnDom.onclick = function() {
        if (textareaDom) {
          fnOpenUrl(textareaDom.value || "");
        }
      }
      clearBtnDom.onclick = function() {
        if (textareaDom) {
          textareaDom.value = "";
        }
      }
      function fnOpenUrl(str) {
        if (str) {
          (str.split("http") || []).forEach(url => {
            url = url.replace(/\s/g, "");
            if (url) {
              url = url && "http" + url;
              if (/(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(url)) {
                window.open(url);
              } else {
                console.log("不是一个网址", url)
              }
            }
          });  
        }
      }

    }
  </script>
</body>
</html>
jio可 2020-04-21
  • 打赏
  • 举报
回复
没用的,会被浏览器当成恶意广告的拦截掉

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧