Friday, May 10, 2024
16
rated 0 times [  19] [ 3]  / answers: 1 / hits: 24509  / 13 Years ago, mon, august 1, 2011, 12:00:00

I want to open a page in a new tab in Google Chrome with window.open(), but I don't want that window to gain focus after it's opened, but to stay in the background.



Is this possible? It only has to work on Google Chrome. It can also use the Google Chrome extension API.



Thanks


More From » google-chrome

 Answers
7

The proper way would be to use extension API:


chrome.tabs.create({url: "http://...", selected: false});

Code should be placed in a background page. If you need it inside a content script you can pass a message to a background page, like so:


//content script
chrome.runtime.sendMessage({link: link});

//background page
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if(message.link) {
chrome.tabs.create({url: message.link, selected: false});
}
});

[#90888] Friday, July 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;