如何使用js调用Google Adsense


现在Google Adsense已经允许使用javascript调用adsense代码。这样做的好处是,对于那些生成html文件的程序,将广告与内容分离之后,我们只要修改js文件就能改变我们的广告样式,而不用重新生成html文件。

js调用广告的方法很简单,在需要插入广告的位置,把原有的广告代码改为嵌入的代码,例如

<script src=”/ads/adsense.js” type=”text/javascript”></script>  

一般的adsense代码如下(注:新代码类似):
==========================================

<script type=”text/javascript”><!–
google_ad_client = “pub-************************”;
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = “234x60_as”;
google_ad_type = “text_image”;
google_ad_channel = “”;
//–>
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js“>
</script>

但是在调用的时候需要进行一些改变
==========================================

document.writeln(“<script type=”text/javascript”><!– “);
document.writeln(“google_ad_client = “pub-************************”; “);
document.writeln(“google_ad_width = 234; “);
document.writeln(“google_ad_height = 60; “);
document.writeln(“google_ad_format = “234x60_as”; “);
document.writeln(“google_ad_type = “text_image”; “);
document.writeln(“google_ad_channel = “”; “);
document.writeln(“//–> “);
document.writeln(“</script> “);
document.writeln(“<script type=”text/javascript” “);
document.writeln(“src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”> “);
document.writeln(“</script>”);
document.writeln(“”)

========================================
HTML转换成JS工具使用:http://www.baizoo.cn/tools/html-js.asp

Categories: 网站相关

Leave a Comment