Chrome 浏览器操作弹出窗口和图标切换不起作用 [英] Chrome Browser Action Popup and icon switch does not work

查看:115
本文介绍了Chrome 浏览器操作弹出窗口和图标切换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 Chrome 扩展程序使用默认弹出窗口时,我无法更改扩展程序状态的图标.如果我禁用 popup.html 状态更改图标正在工作.我使用了一种切换方法来更改图标,该方法在不使用 popup.html 的情况下完美运行.这怎么可能?有人可以帮我吗?

While using a default popup for my Chrome extension, I can't change the icon for the state of the extension. If I disable the popup.html the state changing icons are working. I used a toggle method for changing the icons, which worked perfectly before without using the popup.html. How is that possible? Can anyone help me please?

提前致谢!

推荐答案

当您设置了弹出窗口时,chrome.browserAction.onClicked 不会被触发.

When you have a popup set, chrome.browserAction.onClicked is not fired.

您需要从弹出窗口向您的扩展程序的后台页面发送消息,以通知它有关点击的信息,例如:

You will need to message your extension's background page from the popup to inform it about the click, e.g.:

// background script
chrome.runtime.onMessage.addListener( function (message, sender, sendResponse) {
  if (message.clicked) {
    /* Do the usual onClicked stuff */
  }
});

// popup script
chrome.runtime.sendMessage({clicked : true});

这篇关于Chrome 浏览器操作弹出窗口和图标切换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆