V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
s200612321
V2EX  ›  程序员

关于 chrome 插件开发的问题

  •  
  •   s200612321 · 2014-02-26 20:42:09 +08:00 · 3604 次点击
    这是一个创建于 3705 天前的主题,其中的信息可能已经有所发展或是发生改变。
    关于 chrome 插件开发的问题
    在点击右上角 browser_action 时 插入一个 iframe 到网页的 DOM 中,有些信息不知道如何传递到 iframe 中,比如 网页的网址 。求指点
    8 条回复    1970-01-01 08:00:00 +08:00
    sneezry
        1
    sneezry  
       2014-02-26 20:53:57 +08:00   ❤️ 1
    window.top.document.referrer
    s200612321
        2
    s200612321  
    OP
       2014-02-26 21:06:15 +08:00
    @sneezry 还是会出问题
    Uncaught SecurityError: Blocked a frame with origin "chrome-extension://ipafkdgpadpmhlokecilnbjfnflcojpp" from accessing a frame with origin "http://xxx.com". The frame requesting access has a protocol of "chrome-extension", the frame being accessed has a protocol of "http". Protocols must match.
    我在 iframe 加载完后绑定一个事件
    $(document).ready(function() {
    console.log(window.top.document.referrer);
    }
    还有其他的方法传递消息吗?
    wong2
        3
    wong2  
       2014-02-26 21:25:29 +08:00
    sneezry
        4
    sneezry  
       2014-02-26 21:37:38 +08:00
    哦,那就只能用message了
    sneezry
        5
    sneezry  
       2014-02-26 21:38:34 +08:00
    content script创建iframe的时候把url作为hash或者search写到src里也可以
    rebornix
        6
    rebornix  
       2014-02-26 21:53:20 +08:00
    @sneezry 看到这个帖子就近来看看,果然有你
    s200612321
        7
    s200612321  
    OP
       2014-02-26 21:53:44 +08:00
    @sneezry 不太懂,如何在 content script 创建iframe的时候把url作为hash或者search写到src里
    s200612321
        8
    s200612321  
    OP
       2014-02-26 22:01:10 +08:00
    @sneezry 好像明白了点
    在 content script 创建iframe的时候,在 url 中传递hash 参数,
    比如 <iframe src="/content/index.html?url='xxx/xxx/xxx'"></iframe>
    然后在 iframe 里面就可以获取到 url='xxx/xxx/xxx'
    这样应该可以吧,还没有调试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1022 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:24 · PVG 03:24 · LAX 12:24 · JFK 15:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.