从网站上的链接打开Chrome扩展
Open Chrome extension from link on website
我想从我的网站上的链接打开一个Chrome扩展(充当后台页面)。
我尝试过的东西:
- 使
a
标记链接到扩展的主HTML页面 - 将用户发送到进行302重定向到HTML页面的页面
- 使用Javascript重定向用户,使用
window.location = ...
所有这些都不起作用,而是打开一个about:blank
页面。例外(这似乎很奇怪)是当我使用策略#2并且链接是从我的桌面邮件客户端打开的。
关于如何做到这一点,有什么想法吗?在我们的情况下,请求tabs
权限是不可能的。
试着阅读有关消息从网页传递到扩展的后台页面的信息(听起来像是您想要完成的事情)。
您需要在清单的web_accessible_resources
部分添加taregt HTML文件。例如:
扩展文件结构:
root-dir/
|_____manifest.json
|_____content.js
|_____myfile.html
content.js:
/* Append a link to the web-page's body */
var a = document.createElement("a");
a.href = chrome.extension.getURL("myfile.html");
a.target = "_blank";
a.textContent = "My HTML file";
document.body.appendChild(a);
manifest.json:
{
"manifest_version": 2,
"name": "Test Extension",
"version": "0.0",
"offline_enabled": true,
"content_scripts": [{
"matches": ["*://*/*"],
"js": ["content.js"],
"run_at": "document_end",
"all_frames": false
}],
"web_accessible_resources": ["myfile.html"]
}
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 可以从Chrome扩展修改窗口对象吗
- 从popup.js|Chrome扩展访问DOM
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 在Chrome扩展内部输出Google API调用
- 检查是否存在使用chrome扩展的javascript库
- 从Chrome扩展访问Google Cloud SQL数据库
- Chrome扩展,Chrome.tabs.query的结果未定义
- 为tweet构建chrome扩展
- 在chrome扩展中使用AJAX获取目录中的文件数