我有一个java脚本函数用于一次打开多个不同的标签,如下所示。
如何让标签在加载后自动关闭?
这就是我目前在函数中加载它们的方式:
var URL1 = 'some link here';
var URL2 = 'some link here';
var URL3 = 'some link here';
var URL4 = 'some link here';
var URL5 = 'some link here';
var URL6 = 'some link here';
var URL7 = 'some link here';
var URL8 = 'some link here';
var URL9 = 'some link here';
var URL10 = 'some link here';
var URL11 = 'some link here';
var URL12 = 'some link here';
var URL13 = 'some link here';
var URL14 = 'some link here';
var URL_FINAL1 = encodeURI(URL1);
var URL_FINAL2 = encodeURI(URL2);
var URL_FINAL3 = encodeURI(URL3);
var URL_FINAL4 = encodeURI(URL4);
var URL_FINAL5 = encodeURI(URL5);
var URL_FINAL6 = encodeURI(URL6);
var URL_FINAL7 = encodeURI(URL7);
var URL_FINAL8 = encodeURI(URL8);
var URL_FINAL9 = encodeURI(URL9);
var URL_FINAL10 = encodeURI(URL10);
var URL_FINAL11 = encodeURI(URL11);
var URL_FINAL12 = encodeURI(URL12);
var URL_FINAL13 = encodeURI(URL13);
window.open(URL_FINAL1, '_blank');
window.open(URL_FINAL2, '_blank');
window.open(URL_FINAL3, '_blank');
window.open(URL_FINAL4, '_blank');
window.open(URL_FINAL5, '_blank');
window.open(URL_FINAL6, '_blank');
window.open(URL_FINAL7, '_blank');
window.open(URL_FINAL8, '_blank');
window.open(URL_FINAL9, '_blank');
window.open(URL_FINAL10, '_blank');
window.open(URL_FINAL11, '_blank');
window.open(URL_FINAL12, '_blank');
window.open(URL_FINAL13, '_blank');
});
}
然后上面会打开13个新标签,只是在加载时会提交一些内部数据,因此用户实际上不必在13页上做任何事情,除非让它完全加载。
理想情况下,我希望自动关闭标签,而不是让用户" x"在13个选项卡上
答案 0 :(得分:0)
如果网址具有相同的主机和相同的协议,那么使用load
事件监听器和window.close()
应该可以解决问题:
var onLoadFn = function() { this.close(); };
window.open(URL_FINAL1, '_blank').addEventListener('load', onLoadFn);
答案 1 :(得分:0)
尝试在通过SELF.
命令打开的每个标签中运行window.close();
命令。