作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在查看了 stackoverflow 上的几个相关问题后提出了这个问题。我从 how to detect if an extension is installed 开始.我选择了在某些页面上使用内容脚本向主体添加 div 的方法。这是我如何做到的...
list .json
{
"name": "Install Check",
"content_scripts": [
{
"matches": ["http://host.com/*"],
"js" : ["insert_node.js"]
}
],
"permissions": [
"tabs", "host.com/*"
]
}
insert_node.js(内容脚本)
var insert_node = document.createElement('div');
insert_node.id = "HOST_SITE";
document.body.appendChild(insert_node);
主页
<html>
<head>
</head>
<body>
<h1>This is a host site. Welcome!!!</h1>
<script src="jquery.js"></script>
<script src="notification.js"></script>
</body>
</html>
扩展安装脚本
$(document).ready(function() {
if ($('#HOST_SITE').length > 0) {
alert("you have our extension installed");
} else {
alert("not installed");
}
});
我的问题是,在 chrome 可以将节点注入(inject) DOM 之前,总是弹出带有消息 not_installed
的警报。我在 manifest.json over here 中读到了 run_at
属性.但这也没有解决问题。我尝试了所有三个 document_start
、document_idle
、document_end
值。我在这里做错了什么?
最佳答案
它看起来像是您自己的扩展程序和网站,在这种情况下使用 Inline Installation 会容易得多.
if (typeof chrome !== "undefined" && typeof chrome.app !== "undefined" && chrome.app.isInstalled) {
// extension is installed.
}
关于google-chrome - Chrome 扩展 : How to detect if an extension is installed using Content Scripts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9309068/
我是一名优秀的程序员,十分优秀!