Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top