芒果以 468x60 的经典广告尺寸代码为例,说明 JS 文件调用的方法。
获得广告单元代码如下:
<script type="text/javascript"><!--
google_ad_client = "发布商 ID"
/* 468x60, 创建于 xx-xx-xx */
google_ad_slot = "xxxxxxxxxx"
google_ad_width = 468
google_ad_height = 60
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
得到这段代码后,需要将其转化为 JS 形式:
document.writeln("<script type=\"text\/javascript\"><!--")
document.writeln("google_ad_client = \"发布商 ID\"")
document.writeln("\/* 468x60, 创建于 xx-xx-xx *\/")
document.writeln("google_ad_slot = \"xxxxxxxxxx\"")
document.writeln("google_ad_width = 468")
document.writeln("google_ad_height = 60")
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>")
鉴于手工更改比较麻烦,推荐使用在线 HTML 转 JS 工具,例如:http://www.book560.com/Other/jstohtm.htm
将转换后的代码保存为 JS 文件,调用方法如下:
<script language="JavaScript" src="ggad_468x60.js" type="text/javascript"></script>
作者:水木