简体   繁体   English

使用JavaScript管理多个标签

[英]Manage multiple tabs with JavaScript

Suppose I have a JavaScript bookmarklet. 假设我有一个JavaScript小书签。 When I press this button I would like it to open three predefined URLs and perform an action (clicking the logout button, for example) on each one. 当我按下此按钮时,我希望它打开三个预定义的URL,并对每个URL进行一个操作(例如,单击注销按钮)。 If I were doing this with only one site, I could do window.open("http://stackoverflow.com","_self") and then document.getElementById('logout').click() 如果仅在一个站点上执行此操作,则可以执行window.open("http://stackoverflow.com","_self") ,然后执行document.getElementById('logout').click()

Is there a way I can have this action performed simultaneously in different tabs? 有没有办法让我在不同的标签页中同时执行此操作? If not, how would I go about switching tabs? 如果没有,我该如何切换标签?

You can't. 你不能

Switching tabs is beyond what content-level JavaScript has security permissions to do. 切换标签超出了内容级JavaScript的安全权限。 As far as one JavaScript instance is concerned, there only exists one tab ( window ). 就一个JavaScript实例而言,仅存在一个选项卡( window )。

You would need to write an extension for your browser of choice. 您需要为所选的浏览器编写一个扩展名。

If you're writing for Chrome, check out some documentation on the APIs for tab manipulation with extensions . 如果您使用的是Chrome, 请查看有关API的一些文档,以使用扩展程序进行标签操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM