(Chrome扩展程序)如何务实地从background.html打开弹出窗口 [英] (Chrome Extension)How to pragmatically open the popup window from background.html

查看:594
本文介绍了(Chrome扩展程序)如何务实地从background.html打开弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预先感谢!

我想要实现的是在我的扩展程序在网页上检测到特殊标记时打开弹出窗口。搜索一段时间后,似乎弹出窗口只能在用户单击扩展名时打开。这是真的吗?

或者我可以在浏览器上获得扩展程序图标的位置吗?也许我可以绘制一个窗口,并在扩展图标下显示,使其看起来就像弹出窗口一样。

解决方案

在没有用户点击它的情况下打开扩展窗口...但是,您可以获得扩展弹出页面,以便在新选项卡中打开,如下所示:

1)在清单文件中设置您的后台页面 ... strong>

 background_page:background.html,

这是您运行代码以查看是否检测到特殊标记的位置......后台页面可以不断在后台运行代码,这取决于您设置一个重复循环来检查变量条件是否每隔一段时间都是真实的...

2)启用标签权限清单文件...

 permissions:[tabs],

第3步需要此权限(允许后台页面打开新标签)

3)在后台页面中,调用 创建 并指向扩展程序弹出网址。

  if(condition == true){
chrome.tabs.create({url:popup.html});
}


Thanks in advance!

What I want to achieve is to open the popup window when a special tag is detected on a webpage by my extension. After searching for a while it seems like the popup can only be opened when user clicks the extension. Is it true?

Or could I get the location of my extension's icon on browser? Maybe I could draw a window and display under the extension icon to make it looks just like the popup window.

解决方案

It is impossible to get the extension window to open without a user clicking on it... However, you can get the extension popup page to open in a new tab as follows:

1) Set your background page in your manifest file...

"background_page": "background.html",

This is where you will run the code to see whether the special tag is detected... background pages can constantly run code in the background, and it is up to you to set a repeat loop to check whether you variable condition is true every so often...

2) Enable tabs permission in your manifest file...

"permissions": [ "tabs" ],

This permission is needed for step 3 (Allows the background page to open a new tab)

3) In background page, call create and point to the extension popup url.

if(condition == true){
  chrome.tabs.create({url:"popup.html"});
}

这篇关于(Chrome扩展程序)如何务实地从background.html打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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