简体   繁体   English

让谷歌浏览器扩展自动弹出

[英]Make Google Chrome Extension Automatically Pop Up

I am making a google chrome extension.我正在制作一个谷歌浏览器扩展。 Is there a way to use javascript to make the extension automatically pop-up every time I switch to a new tab without having to click on the icon?有没有办法使用 javascript 让扩展在每次切换到新标签时自动弹出而无需单击图标?

If you want your javascript to be injected into every page (and then you decide if you want to do a in page popup from there).如果您希望将 javascript 注入每个页面(然后您决定是否要从那里进行页面内弹出)。 You would use content scripts.您将使用内容脚本。

https://developer.chrome.com/docs/extensions/mv3/content_scripts/#functionality https://developer.chrome.com/docs/extensions/mv3/content_scripts/#functionality

I have a workaround for you, it is to create a sticky dialog container, create it from your contents.js, make the container style a fixed position.我有一个解决方法,它是创建一个粘性对话框容器,从你的 contents.js 创建它,使容器样式固定为 position。

In ES5 syntax:在 ES5 语法中:

var container = document.createElement('div')
container.style.position = "fixed"
container.style.height = "50px"
container.style.width = " 100px"
container.style.top = "0px"
container.style.right = "0px"
container.style.border = "1px solid black"
container.style.backgroundColor = "white"
document.body.appendChild(container)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM