cod*_*ode 5 javascript google-chrome google-chrome-extension
在我的网络应用程序中,我想放置一段代码,在执行时它应该将当前选项卡重定向到某个扩展页面?
如果我做
window.location = 'chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj';
它会将我重定向到“about://blank”,而不是在该特定扩展页面上。

有人可以帮助我如何实现同样的目标吗?
首先,您需要将 chrome 扩展程序的所有资源放入web_accessible_resources.
您还需要触发重定向行为。您可以使用它,content_scripts并且您将需要permissions特定的域。
最终你将拥有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"
],
Run Code Online (Sandbox Code Playgroud)
和injection.js一样:
location = 'chrome-extension://'+chrome.runtime.id+'/index.html';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1445 次 |
| 最近记录: |