欢迎您! | 积分 | 主页 |
注册 | 登陆 |
官方QQ群: 8807551

JS调用谷歌广告 Google AdSense

发布日期:2010-03-14 11:20:26.0 发布讲师:don 浏览量:147
课程类别:IT电脑开发
学习标签: js 谷歌 广告 Google AdSense
免费在线正则表达式验证工具! 免费在线HTML/JS/CSS调试工具!


点击放大图片-JS调用谷歌广告 Google AdSense

在网页中插入 Google AdSense 广告,一般将源代码直接嵌入主题模板页面。事实上 Google AdSense 支持并允许使用 JS 文件调用。当然前提是不要因任何原因修改代码,或手动影响广告的定位。这会因违反计划政策而被 Google 咔嚓账号。

芒果以 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>
作者:水木

 

 



验证码:验证码

网店名字Don的知识网店
网店店主don
相关课程(共8个):
讲师:don 浏览数:75
2010-07-14 03:43:38.
讲师:don 浏览数:75
2010-06-12 13:28:52.
讲师:don 浏览数:185
2010-05-20 20:25:25.
讲师:don 浏览数:253
2010-05-08 12:39:29.
讲师:don 浏览数:320
2010-04-18 10:56:16.
讲师:don 浏览数:169
2010-03-27 20:20:42.
讲师:don 浏览数:160
2010-03-02 09:21:01.
讲师:don 浏览数:147
2010-01-27 13:51:02.



©2008 - 沪ICP备07037037号 - 简历 - SQL管理 - 邮箱登陆 - RSS阅读