[英]Inject local HTML file into webpage via Chrome Extension using iframe?
[英]Inject javascript in an iframe using chrome extension
有很多关于将 javascript 注入文档页面的问题/答案。 我真正想做的是在文档的 iframe 中注入 javascript。
需要明确的是,该 iframe 与文档不属于同一域。 我已经通过控制台(而不是通过扩展)尝试过它,但无法这样做。
我很好奇这是否可以使用 chrome-extension 来完成?
是的,您可以像这样在 manifest.json 中使用content_scripts属性:
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["content_frame.js"],
"all_frames": true
}],
通过将all_frames
设置为true
您会将content_frame.js
javascript 文件注入/包含到顶级文档和所有 iframe 中。 如果您只需要在 iframe 中注入 javascript 而不是在顶级文档中,您可以像这样检查content_frame.js
文件:
if (parent === top) {
// here you can put your code that will run only inside iframe
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.