2015-08-26 44 views
-1

我为AD服务平台工作,使用CDN服务来投放广告。我们只能将静态文件上传到CDN。如果我们想要服务Adsense或其他广告JS片段,例如。如下所示:如何在另一个JS文件中调用AdSense代码?

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<!-- site 180x150 --> 
<ins class="adsbygoogle" 
    style="display:inline-block;width:180px;height:150px" 
    data-ad-client="ca-pub-xxxx" 
    data-ad-slot="xxxx"></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

创建JS文件并将其上传到CDN不起作用。代码不会被调用。我曾尝试将代码重写为document.write(),但它也不起作用。

任何想法?

回答

0

写入实际上是正确的解决方案,回车是问题。这里代码:

document.write('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!--  responsive pbsqrd --><ins class="adsbygoogle" style="display:block" data-ad- client="ca-pub-xxxx" data-ad-slot="xxxx" data-ad-format="auto"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({});</script>'); 
相关问题