带弹出窗口的chrome.browserAction.onClicked.addListener() [英] chrome.browserAction.onClicked.addListener() with popup
问题描述
我想将Listener添加到触发的事件中,每次点击浏览器图标。我也有一个弹出窗口,点击这个图标出现。
I want to add Listener to the event which fires, everytime the browser icon is clicked. I have also a popup which comes up on click on this icon.
我试过 chrome.browserAction.onClicked.addListener()
,但没有被解雇,后来我看到doc说:
I tried chrome.browserAction.onClicked.addListener()
but didnot get it fired, later i saw that the doc says:
Fired when a browser action icon is clicked.
This event will not fire if the browser action has a popup.
所以,我有popup,所以这个Listener不起作用。在我的情况下,我可以采用什么解决方法将侦听器附加到图标上?
so, I have popup, so this Listener doesnot work. What workaround can I do to attach Listener to icon in my case?
推荐答案
没有解决方法将侦听器附加到该事件,但您可以使用消息传递让您的后台页面知道弹出窗口已打开。
There is no workaround to attach a listener to that event, but you can instead use messaging to let your background page know that the popup was opened.
在弹出窗口中,尽快:
In your popup, as soon as possible:
chrome.runtime.sendMessage({popupOpen: true});
在您的后台页面中:
In your background page:
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
if(message.popupOpen) { /* do your stuff */ }
});
这篇关于带弹出窗口的chrome.browserAction.onClicked.addListener()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!