当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 给网站上的广告“加速”显示的方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 给网站上的广告“加速”显示的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 73 ::
收藏到网摘: n/a

网站建设-给网站上的广告“加速”的方法
第一种是采用iframe+html的方式调用。不管iframe插入在什么地方,加载网页的时候首先是先加载正文内容,然后才加载iframe里的东西。代码如下:
<iframe src="15zone.cn" target="_blank">15zone.cn/blog/post/huazonghua-guanggao.html" target="_blank">http://www.15zone.cn" target="_blank">15zone.cn/blog/post/huazonghua-guanggao.html" frameborder=0 width=336 height=280
scrolling=no marginwidth=0 marginheight=0 ></iframe>
第二种方法是将广告代码放在正文内容后面,采用DIV调用。这样也可以使广告在任何位置显示而不影响正文的loading速度。代码示例如下:
先在欲显示广告的地方插入DIV容器1代码,注意容器的id
<div id="ad" width="336" height="280"></div>
然后在下面的DIV容器2中放置广告代码。该DIV容器可以放在页面body的任何地方。
<div id="adcode" style="display:none">
广告代码
</div>
<script language="javascript">
if(document.all.item("ad") != null) //不推荐这个document.all,可以参考本站的代码
{
ad.innerHTML = adcode.innerHTML;
}
</script>
其原理就是将DIV容器2中的内容设置为不可见(display=none),然后用JS将DIV容器2中的内容放到容器1里显示。
这两种方法都可以用来调用Google Adsense、百度主题推广、阿里联盟或其它广告,通过更改加载顺序使其不影响正文的显示,从而起到了所谓“加速器”的作用。