Mike Warner
Mike Warner

Reputation: 145

programmatically switch to tab in Google Chrome, and open URL if tab not found

I'd need the following functionality for Google Chrome. I didn't find a command line parameter that could help me here.

Any ideas how to solve this?

Upvotes: 5

Views: 7481

Answers (2)

William
William

Reputation: 749

Using Javascript, triggering an alert can have the desired effect. Run this code in your console in one tab and switch to another tab in the same browser.

setTimeout(function(){ 
    alert("Switched tabs");
}, 
5000);

The alert appearing after the timeout will trigger tab switch. Or you can do something similar! This should however be used if absolutely necessary to move user from current tab, like Google Calendar does.

Update 2019

With new versions of Chrome, this no longer works. As pointed out in the comment below, Chrome now shows a small icon in the tab to show a window/alert has been triggered

Upvotes: 0

user529649
user529649

Reputation:

I think Chrome extensions docs - Tabs will help you!

Just to make it clear you can't NOT access anything beyond your Domain in JavaScript because of Same origin policy.

Upvotes: 11

Related Questions