最近有点忙,博客也好久没更新了,作为2019年最后一篇博客,今天给大家带来一款可同时打开多个页面的页面。 注意事项:复制到左侧文本框中的链接要以回车or空格分隔若链接不在新选项卡中打开,请更改浏览器设置.经测试IE, Firefox, Chrome均可用各按钮作用:OpenAll: 打开所有链接Open&RemoveDuplicate: 打开并去掉重复链接CloseAll:关闭所有链接CloseLastBrowsingPages:关闭最近一次打开的链接Reset: 清空 代码如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<title>一次打开多个网页</title>
<style type="text/css">
#Container{ width:100%; }
#Container .gnb {width:880px; padding:5px 25px 5px 0; margin:0 auto; overflow:hidden; position:relative}
#Container .Content{text-align:left;width:880px;margin:0 auto 0 auto;padding:5px 15px 0 10px;}
#Container .Content .Tips{float:right;width:200px;}
#Container .Content .Left{ float:left; width:680px;}
#Container .Content .Clear { clear:both;}
#msg_win{border:1px solid #A67901;background:#EAEAEA;width:240px;position:absolute;right:0;font-size:12px;font-family:Arial;margin:0px;display:none;overflow:hidden;z-index:99;}
#msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;}
.icos a{float:left;color:#833B02;margin:1px;text-align:center;font-weight:bold;width:14px;height:22px;line-height:22px;padding:1px;text-decoration:none;font-family:webdings;}
.icos a:hover{color:#fff;}
#msg_title{background:#FECD00;border-bottom:1px solid #A67901;border-top:1px solid #FFF;border-left:1px solid #FFF;color:#000;height:25px;line-height:25px;text-indent:5px;}
#msg_content{margin:5px;margin-right:0;width:230px;height:126px;overflow:hidden;}
.style1 {
color: #FF0000;
font-style: italic;
}
</style>
<script language="javascript">
var arr=new Array();
var arri = 0;
var content = " <input type='button' value='CloseAll' οnclick='closeAll();' />"
function openMulti()
{
var strs= new Array();
var n = 0;
var m = 0;
var value = document.getElementById("code").value;
Tvalue = Trim(value);
if (!Tvalue.match(/[a-z]/g)||Tvalue=="")
{
alert("请输入链接!");
}
else
{
strs = value.split(/\s+/g);
var str;
var flagBegin = arri;
for (i=0;i<strs.length ;i++ )
{
if ( strs[i].slice(0,7)!="http://" && strs[i].slice(0,7)!="https:/" && strs[i].slice(0,7)!="")
{ str = "http://" + strs[i];
if(!str.match(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/))
{
n++;
}
else
{ arr[arri]=window.open(strs[i]);
m++;
}
}
else if (strs[i]==""){}
else
{
if(!strs[i].match(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/))
{
n++;
}
else
{ arr[arri]=window.open(strs[i]);
m++;
}
}
arri = arri + 1;
}
var flagEnd = arri;
if (m != 0)
{document.getElementById("closeBtn").innerHTML=content+" <input type='button' value='CloseLastBrowsingPages' οnclick='closeBefore("+flagBegin+","+flagEnd+");' />";}
document.getElementById("msg_win").style.display= "block";
document.getElementById("msg_win").style.visibility="visible";
document.getElementById("msg_content").innerHTML= "打开了" + m +"个页面,"+ "关闭了" + n + "个错误页面";
Message.init();
}
}
function removeDuplicate()
{
var strs= new Array();
var n = 0;
var m = 0;
var value = document.getElementById("code").value;
Tvalue = Trim(value);
if (!Tvalue.match(/[a-z]/g)||Tvalue=="")
{
alert("请输入链接!");
}
else
{
strs = value.split(/\s+/g);
var str;
var flagBegin = arri;
var dupi = 0;
for (i=0;i<strs.length ;i++ )
{
if ( strs[i].slice(0,7)!="http://" && strs[i].slice(0,7)!="https:/" && strs[i].slice(0,7)!=""){ str = "http://" + strs[i];}
else if(strs[i]=="") {continue;}
else {str = strs[i];}
if(!str.match(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/))
{
n++;
}
else
{
var clo = 0;
for (var t=1;t+i<strs.length;t++)
{
if ( strs[i]==strs[i+t] && i!=(i+t))
{
clo++;
dupi++;
break;
}
}
if (clo==0)
{
arr[arri]=window.open(str);
arri = arri + 1;
m++;
}
}
}
var flagEnd = arri;
if (m != 0)
{
document.getElementById("closeBtn").innerHTML=content+" <input type='button' value='CloseLastBrowsingPages' οnclick='closeBefore("+flagBegin+","+flagEnd+");' />";}
document.getElementById("msg_win").style.display= "block";
document.getElementById("msg_win").style.visibility="visible";
document.getElementById("msg_content").innerHTML= "打开了" + m +"个页面,"+ "关闭了" + n + "个错误页面"+ "和" + dupi + "个重复页面";
Message.init();
}
}
function closeAll() {
for (i=0;i<arr.length ;i++)
{
if (arr[i])
{ arr[i].close();
}
else
{ continue; }
}
arri = 0;
document.getElementById("closeBtn").innerHTML="";
}
function closeBefore(begin,end) {
for (i=begin;i<=end ;i++ )
{
if (arr[i])
{ arr[i].close();
}
else
{ continue; }
}
document.getElementById("closeBtn").innerHTML=content;
}
function Trim(m){
while((m.length>0)&&(m.charAt(m.length-1)==' '))
{m = m.substring(0, m.length-1);}
return m;
}
function Reset(){
document.getElementById("code").value = "";
}
window.onbeforeunload = function(){
return "关闭或刷新此页将会导致:不能用本工具关闭以前打开的网页。继续?";
}
</script>
</head>
<body>
<div id="Container">
<div class="gnb">
<p align="center">一次打开多个网页</p>
</div>
<div class="Content">
<div class="Left">
<textarea id="code" cols="78" rows="32"></textarea>
<div id="openBtn" style="float:left">
<input type="button" value="OpenAll" οnclick="openMulti();" />
<input type="button" value="Open&RemoveDuplicate" οnclick="removeDuplicate();" />
<input type="button" name="Reset" id="button" value="Reset" οnclick="Reset();"/>
</div>
<div id="closeBtn" style="float:left"></div>
<br /><br /><br /><br /><br />
</div>
<div class="Tips">
<p>注意事项:</p>
<p>复制到左侧文本框中的链接要以<span class="style1">回车or空格</span>分隔</p>
<p>若链接不在新选项卡中打开,请更改浏览器设置.</p>
<p>经测试IE, Firefox, Chrome均可用</p>
<p>各按钮作用:</p>
<p>OpenAll: 打开所有链接</p>
<p>Open&RemoveDuplicate: 打开并去掉重复链接</p>
<p>CloseAll:关闭所有链接</p>
<p>CloseLastBrowsingPages:关闭最近一次打开的链接</p>
<p>Reset: 清空</p>
</div>
<div class="Clear"> </div>
</div>
<div id="msg_win" style="display:none;top:490px;visibility:hidden;opacity:1;">
<div class="icos"><a id="msg_close" title="close" href="###">×</a></div>
<div id="msg_title">提示</div>
<div id="msg_content"></div>
</div>
</div>
<script language="javascript">
var Message={
close: function() {
this.win.style.display = 'none';
},
setOpacity: function(x) {
var v = x >= 100 ? '': 'Alpha(opacity=' + x + ')';
this.win.style.visibility = x<=0?'hidden':'visible';
this.win.style.filter = v;
this.win.style.opacity = x / 100;
},
show: function() {
clearInterval(this.timer2);
var me = this,fx = this.fx(0, 100, 0.1),t = 0;
this.timer2 = setInterval(function() {
t = fx();
me.setOpacity(t[0]);
if (t[1] == 0) {clearInterval(me.timer2) }
},10);
},
fx: function(a, b, c) {
var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1;
return function() {return [a += cMath((b - a) * c), a - b]}
},
getY: function() {
var d = document,b = document.body, e = document.documentElement;
var s = Math.max(b.scrollTop, e.scrollTop);
var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
var h2 = this.win.offsetHeight;
return {foot: s + h + h2 + 2+'px',top: s + h - h2 - 2+'px'}
},
moveTo: function(y) {
clearInterval(this.timer);
var me = this,a = parseInt(this.win.style.top)||0;
var fx = this.fx(a, parseInt(y));
var t = 0 ;
this.timer = setInterval(function() {
t = fx();
me.win.style.top = t[0]+'px';
if (t[1] == 0) {
clearInterval(me.timer);
me.bind();
}
},10);
},
bind:function (){
var me=this,st,rt;
window.onscroll = function() {
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st = setTimeout(function() {
me.win.style.top = me.getY().top;
me.show();
},600);
};
window.onresize = function (){
clearTimeout(rt);
rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
}
},
init: function() {
function $(id) {return document.getElementById(id)};
this.win=$('msg_win');
var set={minbtn: 'msg_min',closebtn: 'msg_close',title: 'msg_title',content: 'msg_content'};
for (var Id in set) {this[Id] = $(set[Id])};
var me = this;
this.closebtn.onclick = function() {me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];
this.closebtn.innerHTML=this.char[2];
setTimeout(function() {
me.win.style.display = 'block';
me.win.style.top = me.getY().foot;
me.moveTo(me.getY().top);
},0);
return this;
}
};
</script>
</body>
</html>