来自 Google Adsense 的 Javascript 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2541797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:49:32  来源:igfitidea点击:

Javascript errors from Google Adsense

javascriptadsense

提问by Arjun

On several of my adsense running sites, I have been getting the following errors:

在我的几个运行 Adsense 的网站上,我一直收到以下错误:

Unable to post message to [http://]googleads.g.doubleclick.net. Recipient has origin http://www.anekdotz.com.

Unsafe JavaScript attempt to access frame with URL [http://]www.anekdotz.com/from frame with URL [http://]googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9099580055602120&output=html&h=250&slotname=9210181593&w=300&flash=10.0.42&url=http%3A%2F%2Fwww.anekdotz.com%2F&dt=1269901036429&correlator=1269901036438&frm=0&ga_vid=711000587.1269901037&ga_sid=1269901037&ga_hid=654061172&ga_fc=0&u_tz=-240&u_his=2&u_java=1&u_h=900&u_w=1440&u_ah=878&u_aw=1436&u_cd=24&u_nplug=10&u_nmime=101&biw=1365&bih=806&eid=44901212&fu=0&ifi=1&dtd=153&xpc=Xkfk1oufPQ&p=http%3A//www.anekdotz.com. Domains, protocols and ports must match.

无法向 [ http://]googleads.g.doubleclick.net发布消息。收件人有来源 http://www.anekdotz.com

不安全的 JavaScript 尝试从 URL [ http://]googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9099580055602120&output= 的框架访问 URL [ http://]www.anekdotz.com/的框架HTML&H = 250&广告位名称= 9210181593&W = 300&闪光= 10.0.42&URL = HTTP%3A%2F%2Fwww.anekdotz.com%2F&DT = 1269901036429&相关= 1269901036438&FRM = 0&ga_vid = 711000587.1269901037&ga_sid = 1269901037&ga_hid = 654061172&ga_fc = 0&u_tz = -240&u_his = 2&u_java = 1&u_h = 900&u_w = 1440&u_ah = 878&u_aw = 1436&u_cd = 24&u_nplug = 10&u_nmime = 101&BIW = 1365&波黑= 806&EID = 44901212&福= 0&IFI = 1&DTD = 153&XPC = Xkfk1oufPQ&p = HTTP%3A // www.anekdotz.com域、协议和端口必须匹配。

(from the Chrome javascript console)

(来自 Chrome javascript 控制台)

The ads seem to show properly and it doesn't affect my native javascript code. However sometimes these errors seem to slow down page loading. How can I fix this problem?

广告似乎可以正常显示,并且不会影响我的原生 JavaScript 代码。然而,有时这些错误似乎会减慢页面加载速度。我该如何解决这个问题?

(I modified the URLs to let me post this as I'm a new user)

(我修改了 URL 以让我发布此内容,因为我是新用户)

回答by bobince

Google have messed up their script. There's not much you can do about it.

谷歌搞砸了他们的脚本。你无能为力。

For some reason http://pagead2.googlesyndication.net/pagead/expansion_embed.js, included in the parent page by the AdSense scripts, is trying to send information about the advert into a newly-written <iframe>created to hold the advert, using the new HTML5 postMessagefacility:

出于某种原因http://pagead2.googlesyndication.net/pagead/expansion_embed.js,由 AdSense 脚本包含在父页面中的 ,正尝试<iframe>使用新的 HTML5 postMessage工具将有关广告的信息发送到新编写的用于保存广告的内容中:

            ha(this, function (f, e) {
                d[Pa](this.a[A]+"|"+f+":"+e, this.la)
            });

Yeah. Some nice minified/obfuscated code there. Trust me, Pais 'postMessage'!

是的。那里有一些不错的缩小/混淆代码。相信我,Pa'postMessage'

The targetOriginargument in this call, this.lais set to http://googleads.g.doubleclick.net. However, the new iframe was written with its srcset to about:blank. This doesn't match the target origin, so the browser must refuse to send the message. Only Chrome seems to be dropping an actual whinge to the console log about it though.

targetOrigin此调用中的参数this.la设置为http://googleads.g.doubleclick.net。但是,新的 iframe 是在其src设置为about:blank. 这与目标来源不匹配,因此浏览器必须拒绝发送消息。不过,似乎只有 Chrome 会在控制台日志中删除有关它的实际抱怨。

No idea why it's doing this at all, never mind why it's not just using '*'as a target origin... I'm not really feeling like wading into the obfuscated script to find out. However, this error should not cause page loading to slow down. If you're seeing pauses it's usually resolving and fetching other external scripts.

根本不知道它为什么要这样做,更不用说为什么它不只是'*'用作目标来源......我真的不想涉足混淆脚本以找出答案。但是,此错误不应导致页面加载速度变慢。如果您看到暂停,则通常是在解析和获取其他外部脚本。

回答by thomasrutter

Google's trying to exploit a browser quirk whereby some browsers ignore the same-origin policy for windows with about:blank as the URL, allowing that window to submit XMLHttpRequest or, in this case, postMessage requests to any site.

谷歌试图利用浏览器的一个怪癖,即一些浏览器会忽略以 about:blank 作为 URL 的窗口的同源策略,允许该窗口提交 XMLHttpRequest,或者在这种情况下,向任何站点提交 postMessage 请求。

As far as I know, browsers have recently been disabling this behaviour. You must have one such patched browser.

据我所知,浏览器最近一直在禁用这种行为。你必须有一个这样的修补浏览器。

Hopefully, this broken functionality doesn't affect your ability to earn money from the ads.

希望这个损坏的功能不会影响您从广告中赚钱的能力。

It's annoying for your site to generate Javascript errors through no fault of your own, but it is a possibility you must accept when you run someone else's Javascript on your page.

您的网站在没有您自己的过错的情况下生成 Javascript 错误很烦人,但是当您在您的页面上运行其他人的 Javascript 时,您必须接受这种可能性。

回答by risnandar

It's normal because your browser prevents CSRF attacks from other websites.

这是正常的,因为您的浏览器会阻止来自其他网站的 CSRF 攻击。

To allow googleads...to access your website and solve this problem, create a file named crossdomain.xmlin your webroot and fill it with the following content:

要允许googleads...访问您的网站并解决此问题,请crossdomain.xml在您的 webroot 中创建一个名为的文件并填写以下内容:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy 
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="googleads.g.doubleclick.net" />
</cross-domain-policy>

To test it, go to your domain http://your-domain.com/crossdomain.xmland make sure there are no errors for that page. You also allowed to use wildcards, etc (look at reference). When you're done, refresh your page. Hope that helps.

要测试它,请转到您的域http://your-domain.com/crossdomain.xml并确保该页面没有错误。您还允许使用通配符等(请参阅参考资料)。完成后,刷新页面。希望有帮助。

Live example: http://www.blanjamudah.com/crossdomain.xml

现场示例:http: //www.blanjamudah.com/crossdomain.xml

Reference: http://en.wikipedia.org/wiki/Cross-site_request_forgeryhttp://curtismorley.com/2007/09/01/flash-flex-tutorial-how-to-create-a-crossdomainxml-file/

参考:http: //en.wikipedia.org/wiki/Cross-site_request_forgery http://curtismorley.com/2007/09/01/flash-flex-tutorial-how-to-create-a-crossdomainxml-file/

回答by jfrprr

For those who land on this page after searching for the domain and protocol error code:

对于那些在搜索域和协议错误代码后登陆此页面的人:

AdSense has released a new async versionof their javascript that addressed the cross-domain errors being generated when we used their older embed code. When we used their standard embed code on our AJAX-heavy site, we got the cross-domain error. When we implemented their async code, and in combination with a properly defined crossdomain.xmlthe cross-domain error went away.

AdSense 发布了一个新的异步版本的 javascript,解决了我们使用旧的嵌入代码时产生的跨域错误。当我们在我们的 AJAX 密集型站点上使用他们的标准嵌入代码时,我们遇到了跨域错误。当我们实现他们的异步代码并结合正确定义的 crossdomain.xml 时,跨域错误就消失了。

回答by Chaoley

A crossdomain.xml file in the site root allowing access to googleads.g.doubleclick.net should fix it.

允许访问 googleads.g.doubleclick.net 的站点根目录中的 crossdomain.xml 文件应该可以修复它。

See this page, http://www.warriorforum.com/adsense-ppc-seo-discussion-forum/458906-adsense-blank-space-problem.html

看到这个页面,http://www.warriorforum.com/adsense-ppc-seo-discussion-forum/458906-adsense-blank-space-problem.html

回答by Peter

Just got a similar problem. Not sure if it's related, but I'll explain anyway.

刚刚遇到了类似的问题。不确定它是否相关,但无论如何我都会解释。

I had two ads showing on my page and wanted to "refactor" the code by only calling this script once at the end of the page:

我在我的页面上展示了两个广告,并希望通过仅在页面末尾调用此脚本一次来“重构”代码:

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

My ads broke and I figured out that this script tag has to be placed just after each ads var script:

我的广告坏了,我发现这个脚本标签必须放在每个广告 var 脚本之后:

<script type="text/javascript"><!--
google_ad_client = "ca-pub-872346872364872364";
google_ad_slot = "719238712983";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>

But when I had reverted my changes the first script tag was still also placed at the bottom of my page and thusly trying to load another one of my script-tags as an ad. This failed and I got this error you saw.

但是当我恢复我的更改时,第一个脚本标签仍然放在我的页面底部,因此试图加载另一个脚本标签作为广告。这失败了,我收到了你看到的这个错误。

So check that you keep the two ads script tags after eachother and no place else, ex:

因此,请检查您是否将两个广告脚本标签保持在彼此之后而不是其他地方,例如:

<script type="text/javascript"><!--
google_ad_client = "ca-pub-872346872364872364";
google_ad_slot = "719238712983";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

回答by mahemoff

This seems to be a case of the error message masking the real cause. The real cause is probably some kind of Adsense misconfiguration; unfortunately Adsense doesn't seem to do sufficient checks to give a more relevant error message.

这似乎是错误消息掩盖了真正原因的情况。真正的原因可能是某种 Adsense 配置错误;不幸的是,Adsense 似乎没有做足够的检查来提供更相关的错误消息。

I had this error myself and came to this conclusion after researching the forums, where some people reported it was fixed after verifying their bank account or whatever. In my case, my server-side environment was messing with the google_ad_client parameter, so the real problem was that parameter being null. Once I fixed that, ads were showing and no more error message.

我自己也有这个错误,并在研究论坛后得出这个结论,有些人报告说在验证他们的银行帐户或其他任何东西后它已修复。就我而言,我的服务器端环境弄乱了 google_ad_client 参数,所以真正的问题是该参数为空。一旦我解决了这个问题,广告就会显示出来,并且没有更多的错误消息。

So in practice, it's really nothing to do with same-origin policy. Now that the adsense code is correct, I'm even now able to show ads when running on localhost, as well as on the server.

所以在实践中,它真的与同源策略无关。现在,adsense 代码是正确的,我什至现在可以在本地主机和服务器上运行时显示广告。

回答by Vinnie James

Simply moving <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>to the top of the page above the ads, instead of below, fixed this for me

只需移动<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>到广告上方的页面顶部,而不是下方,即可为我解决此问题

回答by JayChase

In the Sites tab in your Google Adsense dashboard (web or app version). Make sure your site is setup with your-domain.com(or whichever tld) as the domain and www.your-domain.comas a subdomain.

在 Google Adsense 信息中心(网页版或应用版)的网站标签中。确保您的站点设置为your-domain.com(或任何一个 tld)作为域和www.your-domain.com作为子域。