作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 web 应用程序中,我想放置一个代码,在执行时将当前选项卡重定向到某个扩展页面?
如果我这样做
window.location = 'chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj';
它将我重定向到不在那个特定扩展页面上的“about://blank”。
谁能帮我实现同样的目标。
最佳答案
首先,您需要将 chrome 扩展程序的所有资源放入 web_accessible_resources
。
您还需要触发重定向行为。您可以使用 content_scripts
执行此操作,并且您需要特定域的权限
。
最终你会得到像这样的mainfest.json:
"permissions": [
"*://example.com/*"
],
"content_scripts": [{
"js": ["injection.js"],
"matches": ["*://www.example.com/*", "*://example.com/*"]
}],
"web_accessible_resources" : [
"index.html",
"main.js",
"favicon.ico"
],
和 injection.js 像:
location = 'chrome-extension://'+chrome.runtime.id+'/index.html';
关于javascript - 如何重定向到 chrome 中的扩展页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29305668/
我是一名优秀的程序员,十分优秀!