Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

javascript - Chrome Extension: Open new tab without losing popup focus

I have a simple list of research links on a Chrome Extension:

<a href="http://www.example1.com" target="_blank">Research Link 1</a>
<a href="http://www.example2.com" target="_blank">Research Link 2</a>
<a href="http://www.example3.com" target="_blank">Research Link 3</a>

On any webpage, I could ctrl+click all three links, opening new tabs in the background. However, this doesn't seem to be the case with a Chrome Extension Popup. If you ctrl+click on a link, the extension closes the popup, which prevents you from clicking more than one link at any time.

I've tried an on-click chrome.tabs.create approach which is described in several other posts, but that seems similar to just clicking target="_blank" as it just opens a new tab with focus.

chrome.tabs.create({url: 'http://www.google.com'});

Is there any way to open a new tab without focus (ctrl+click), while still allowing the extension popup to remain visible in the current tab so that the user can click a second, third, or fourth link? That way the user doesn't have to rerun the extension several times, which takes time as it has to authenticate and query for the data all over again.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, there is an option for create:

chrome.tabs.create({url: 'http://www.google.com', active: false});

I'm using it in one of my extensions exactly as you described.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...