javascript 错误 - HTML 中的异步 AdSense 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21661924/
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
Error - Asynchronous adsense code in HTML
提问by Aws Ahmed
I'm a blogger and I monetize my blog with adsense. While coding or in fact adding asynchronous code inside <head></head>
tag of my blog it appears that I have to add it like this:
我是一名博主,我通过 Adsense 将我的博客货币化。在编码或实际上在<head></head>
我博客的标签中添加异步代码时,似乎我必须像这样添加它:
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
instead of like this:
而不是这样:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
Otherwise it will show me an error. Can anyone explain why? Do you know if I'm allowed to add this (according to adsense)?
否则它会告诉我一个错误。谁能解释为什么?你知道我是否可以添加这个(根据 Adsense)?
回答by Muhammad Nouman Khalid
Use this code instead on any of them... I'm currently using this...Try it
在其中任何一个上使用此代码...我目前正在使用此...试试看
<script async='async' src='http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'></script>
回答by SLaks
You're writing an XHTML document (either because of the Content-Type
or an XML declaration).
您正在编写 XHTML 文档(由于Content-Type
或 XML 声明)。
Therefore, the entire document must be valid XML.
因此,整个文档必须是有效的 XML。
Unlike regular HTML, all XML attributes must have values.
与常规 HTML 不同,所有 XML 属性都必须具有值。
回答by RyanNiccolls.com
I have a solution for the same problem with Hubspot Tracking Code with Blogger.
我有一个解决与 Blogger 的 Hubspot 跟踪代码相同的问题的方法。
When adding the following code to the theme HTML in Blogspot, I get an error.
将以下代码添加到 Blogspot 中的主题 HTML 时,出现错误。
Error parsing XML, line 2490, column 62: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
解析 XML,第 2490 行,第 62 列时出错:与元素类型“脚本”关联的属性名称“async”必须后跟“=”字符。
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/xxxxxx.js"></script>
<!-- End of HubSpot Embed Code -->
I fixed it be using the above fix changing async defer
to async="async defer"
我修复它是使用上述修复更改async defer
为async="async defer"
<!-- Start of HubSpot Embed Code 17/03/2017-->
<script type="text/javascript" id="hs-script-loader" async="async defer" src="//js.hs-scripts.com/2336222.js"></script>
<!-- End of HubSpot Embed Code -->