Suppose I have a JavaScript bookmarklet. 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. If I were doing this with only one site, I could do window.open("http://stackoverflow.com","_self") and then 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. As far as one JavaScript instance is concerned, there only exists one tab (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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top