我正在试验 Chrome 插件。我试图找到所有 <p>
html 页面上的标记并更改 font-family
/size
/color
这些标签。基本上我只是在试验这个。
这是我到目前为止所做的。
一个。 list .json
{
"name": "ABC XYZ",
"description": "La la la...",
"version": "1",
"browser_action": {
"default_title": "ABC",
"default_icon": {
"19": "icons/logo.png"
},
"default_popup": "mydefault.html"
},
"manifest_version": 2
}
B.我的默认.html
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#do-magic").click(function() {
// do something here with the page html.
// change font-family
$("body").append("test");
});
});
</script>
</head>
<body>
<span id="do-magic">Start</span>
</body>
</html>
当打包并加载到 chrome 时,除了我尝试访问页面元素的点击事件外,这一切都有效。
点击事件不起作用。控制台中也没有打印任何内容。
请指教。
最佳答案
根据内容安全政策,您不能在 Chrome 扩展程序中使用内联脚本。这就是您的代码未被执行的原因。
您必须将其移动到一个单独的文件中。参见 here .
关于jquery - 如何使用 chrome 扩展/插件访问 HTML 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22857508/