javascript - chrome 插件iframe交互
大家讲道理
大家讲道理 2017-04-10 12:43:37
0
2
590

我需要插件读取一个iframe中的数据,这个iframe是我可以控制的,我写的插件把这个iframe插入到其他页面中,现在我需要插件读取iframe中的数据,我现在用cookies交互数据,有什么其他方法吗?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
伊谢尔伦

建议使用 contentscript,这样可以让你的扩展直接和 iframe 页面通信,交换信息。
文档:http://developer.chrome.com/extension...

不过需要在扩展中设置 all_frames 为 true ,以保证 contentscript 能够加载到 iframe 中去。

我有个扩展和你的需要类似,都是要与一个自己可控的 iframe 通信。
https://github.com/greatghoul/music1g...
而且需要 iframe 的页面主动向扩展发送消息,执行动作,使用自定义事件实现,iframe 参考 http://music1g.sinaapp.com/commander

迷茫

html5 的 window.postMessage, 可以向 iframe 发送消息(并且可以跨域)
https://developer.mozilla.org/en-US/d...

另外,Cookie交换数据显然可以用localStorage来替代

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template