点击<a> link in chrome extension, how can popup.html keep open state?

时间:2016-04-18 07:52:17

标签: javascript jquery html google-chrome google-chrome-extension

I'm doing a Chrome extension about looking though posts from a forum.

Now,I can get some posts' links and I put these links into in my popup.html like this:

<a href="post's link" target="_blank">post's title</a>

Then when I click the link, a new tab will be opened, but the popup.html page will disappear.

And when I click with pressing , new tab will be opened, but problem still exists.

Now, I want to know if I can open a new tab by clicking a link, and in the meantime I can keep my popup.html page still Show.

I refer to the documentation of chrome extension development, but I still can not solve this problem.

So, can this be realized? And how?

Thanks!

2 个答案:

答案 0 :(得分:1)

我认为您不能使用target="_blank"执行此操作,请参阅FAQ Persist Popups

  当用户将注意力集中在弹出窗口之外的浏览器的某些部分时,

弹出窗口会自动关闭。用户点击后无法保持弹出窗口打开。

然而(感谢@Bob den os的想法),您可以将chrome.tabs.createactive: false一起使用,这样就可以在没有焦点的情况下创建新标签,您可以保持弹出窗口打开

chrome.tabs.create({
    url: "xxx.com",
    active: false
});

答案 1 :(得分:0)

Chrome扩展程序弹出窗口需要重点保持打开状态。

How to keep Google Chrome Extension popup open?

可以将弹出窗口打开到新选项卡中。这不需要专注于保持开放。

chrome.tabs.create({ url: chrome.extension.getURL('popup.html')});