search

Home  >  Q&A  >  body text

javascript - chrome 插件iframe交互

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

大家讲道理大家讲道理2897 days ago589

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-10 12:45:37

    建议使用 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

    reply
    0
  • 迷茫

    迷茫2017-04-10 12:45:37

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

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

    reply
    0
  • Cancelreply