我在 popup.html 中添加了 iframe 和 jquery。
<iframe id="xyz" border="0" src="https://xyz.com/test"></iframe>
并尝试通过控制台使用此命令访问此 iframe 的元素:
$("#xyz").contents().find("body").fadeIn();
但它给出了这个错误:
Unsafe JavaScript attempt to access frame with URL https://xyz.com/test from frame with URL chrome-extension://my-extension-id/popup.html. The frame requesting access has a protocol of 'chrome-extension', **the frame being accessed has a protocol of 'https'. Protocols must match**
我在谷歌上搜索了这个错误,但没有这样的错误。他们都说域必须匹配等等。但是这个说只有协议(protocol)必须匹配。我该如何解决这个协议(protocol)问题?
我的 list 文件中有这一行。
"permissions": [
"*://xyz.com/*"
]
最佳答案
似乎是 same origin policy 的问题。
尝试遵循 this discussion 中提到的解决方案。此外,在尝试使用 jQuery 之前,请先尝试通过 native Javascript 进行操作。
关于google-chrome - 访问 chrome-extension 上的 https iframe 元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13431288/