Focus Prevention window.open

I want to open the page in a new tab in Google Chrome using window.open (), but I do not want this window to get focus after it opens, but to stay in the background.

Is it possible? It should work only in Google Chrome. It can also use the Google Chrome extension API.

thank

+9
javascript google-chrome google-chrome-extension
Aug 01 2018-11-11T00:
source share
6 answers

The correct way is to use the extension API:

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

The code should be placed on the man page. If you need this inside the contents of the script, you can pass the message to the wallpaper, for example:

 //content script chrome.runtime.sendMessage({link: link}); //background page chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { if(message.link) { chrome.tabs.create({url: link, selected: false}); } }); 
+9
Aug 01 '11 at 15:37
source share
 window.open(url, name, features); window.focus(); 

You will see a new window for a short time.

+2
Aug 01 2018-11-11T00:
source share

All browsers have a way out.

 function openURL(url, opt){ if (opt == 0){ // current window window.location = url; }else if (opt == 1){ // new window window.open(url); }else if (opt == 2){ // background window window.open(url); self.focus(); } } 

Thus, using this, you can do whatever you want.

 openURL( "http://www.google.com", 0 ) --> open in same window openURL( "http://www.google.com", 1 ) --> open in new window openURL( "http://www.google.com", 2 ) --> open in new window but in background. 
+2
Aug 01 2018-11-11T00:
source share

Yes you can do it:

 var myWindow = window.open(url,name,features); myWindow.blur(); 
+1
Mar 14 '16 at 14:35
source share

Try the following: (chrome only)

 var myWindow = window.open(url,name,features); window.open().close(); 
0
Aug 16 '17 at 12:01
source share

Activate the parent window from the child or activate self when the child is open.

-2
Aug 01 '11 at 11:00
source share



All Articles