AdSense未与Turbolinks合作

时间:2013-06-13 21:19:58

标签: javascript ruby-on-rails adsense turbolinks

我一直在

Unsafe JavaScript attempt to access frame with URL http://lolfantasy.net/ from frame with URL http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-874208342468282…535&u_cd=24&u_nplug=8&u_nmime=81&biw=1520&bih=454&fu=0&js=uds&eid=37464000. Domains, protocols and ports must match.

使用带有Turbolinks的adsense。

我正在使用此page中的代码。它仍然无法正常工作。广告有时会短暂显示,但之后会消失。

2 个答案:

答案 0 :(得分:2)

使用Turbolinks 5尝试此解决方案

<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" data-turbolinks-eval="false"></script>

身体 Adsense代码

 <ins class="adsbygoogle"
 style="display:block"
 data-ad-client="ca-pub-XXXXX"
 data-ad-slot="XXX"
 data-ad-format="auto"></ins>

JavaScript

function adsenseAds() {
var ads = document.querySelectorAll('.adsbygoogle');

ads.forEach(function(ad) {
(adsbygoogle = window.adsbygoogle || []).push({});
});
}

document.addEventListener('turbolinks:load', adsenseAds);

答案 1 :(得分:-1)

看看这篇文章,看看它是否对您有帮助。

http://reed.github.io/turbolinks-compatibility/google_adsense.html

关键部分在页面上:抓取他们正在清除广告(CoffeeScript中的示例)

clearAds: ->
    @ads = {}
    window.google_prev_ad_slotnames_by_region[''] = '' if window.google_prev_ad_slotnames_by_region
    window.google_num_ad_slots = 0