V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jeffjade
V2EX  ›  问与答

接入 GoogleAdsense 代码报错?

  •  
  •   jeffjade · 2016-03-03 14:12:37 +08:00 · 2411 次点击
    这是一个创建于 3191 天前的主题,其中的信息可能已经有所发展或是发生改变。

    获取到 Google 代码:

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
        </script>
        <!-- Google 内容广告 -->
        <ins class="adsbygoogle"
            style="display:block"
            data-ad-client="xxxxx"
            data-ad-slot="xxxxxx"
            data-ad-format="auto">
        </ins>
        <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    

    加入到网页 div 中。会操错如下:

    Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.jeffjade.com" from accessing a frame with origin "http://googleads.g.doubleclick.net". Protocols, domains, and ports must match.

    目测看着像是跨域了,搜索网上方法,采用

    <script>document.domian='jeffjade.com'</script>
    

    等等一系列尝试,还是会有各种问题,比如

    Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.jeffjade.com" from accessing a frame with origin "https://googleads.g.doubleclick.net". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

    网上对这个资料目测不多;所以在这里请教下,这问题该如何解决呢?感谢。

    ershisi
        1
    ershisi  
       2016-03-03 15:00:26 +08:00
    Protocols, domains, and ports must match. 怎么感觉问题是这块。接触过但是不熟悉。
    [Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.jeffjade.com" from accessing a frame with origin "https://googleads.g.doubleclick.net". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.]这个是说需要 https
    jeffjade
        2
    jeffjade  
    OP
       2016-03-03 16:23:14 +08:00
    之后发现是自己 Chrome 装了 markdown-here 造成的。 -_-#
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2977 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:56 · PVG 22:56 · LAX 06:56 · JFK 09:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.