【发布时间】:2012-07-24 22:39:31
【问题描述】:
我的 chrome 扩展文件夹中有一个页面 iframe.html。我希望它显示在我当前的网页中。这就是问题所在,当我单击 iframe 中的按钮时,如何关闭 iframe?我试过这样的代码:
window.parent.iframe.hide()
但它不会出现错误:
Unsafe JavaScript attempt to access frame with URL
但是我清楚地阅读了evernote的源文件。它有一些代码,如
window.parent.$readable.hide()
为什么evernote 的扩展程序可以工作,但我的扩展程序显示一些错误?这是我应该在 manifest.json 中做的事情吗?这是我的清单文件。
{
"name": "Reader",
"version": "1.0",
"manifest_version": 2,
"description": "A great start!",
"browser_action": {
"default_icon": "icon.png"
},
"background": {"scripts": ["background.js"]},
"permissions": [
"tabs", "<all_urls>"
],
"web_accessible_resources": [
"iframe/index.html"
]
}
【问题讨论】:
-
@Larry:不是重复的:这个问题涉及一个 iframe,它被添加为 扩展程序自身功能的一部分,而该问题涉及“自然发生的“ iframe 是网页的正常部分。这个问题涉及注入 iframe 的脚本权限,该问题询问为什么在页面加载时间后页面添加的 iframe 中没有注入内容脚本。
-
我发现evernote明显没有为iframe提供src属性。他们只是使用模板并将
javascript: <the template>设置为src。我还没有尝试过这种方法。但我认为这应该可行。 -
我不用上面的技巧就解决了这个问题。我只是通过chrome扩展api向后台页面发送消息,然后让后台页面将消息发送到内容脚本。它看起来很复杂,但它现在解决了问题。
-
@aisensiy 你找到比上面更好的解决方案了吗?
标签: javascript google-chrome iframe google-chrome-extension cross-domain