随页面移动的浮动广告代码

网页中用标准格式时,如:
头部<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
在加入浮动广告时,发现不能随着页面移动,后发现163的这样写可以:
   //<![CDATA[
   var adLeftSrc = "http://adimg.163.com/homepage/eachnet/eachnet060510_8080.gif"
   var adLeftFlash = ""
   var adLeftHref = "http://adfarm.mediaplex.com/ad/ck/4080-35044-9511-1?cn=netease;flt060508yj;hp"
   var adLeftWidth = 80
   var adLeftHeight = 80
   var adRightSrc = ""
   var adRightFlash = ""
   var adRightHref = ""
   var adRightWidth = 80
   var adRightHeight = 80
   var marginTop = 10
   var marginLeft = 1
   var navUserAgent = navigator.userAgent
   function load(){
    judge();
    move();
   }
   function move() {
    judge();
    setTimeout("move();",80)
   }
   function judge(){
    if (navUserAgent.indexOf("Firefox") >= 0 || navUserAgent.indexOf("Opera") >= 0) {
     if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adLeftHeight - marginTop + 'px';}
     if (adRightSrc != "") {
      document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adRightHeight - marginTop + 'px';
      document.getElementById("adRightFloat").style.left = ((document.body.clientWidth > document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
     }
    }
    else{
     if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adLeftHeight - marginTop + 'px';}
     if (adRightSrc != "") {
      document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adRightHeight - marginTop + 'px';
      document.getElementById("adRightFloat").style.left = ((document.documentElement.clientWidth == 0)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
     }
    }
    if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.left = marginLeft + 'px';}
   }
   if (adLeftSrc != "") {
    if (adLeftFlash == "flash") {
     document.write("<div id=\"adLeftFloat\" style=\"position: absolute;width:" + adLeftWidth + ";\"><a href=\"" + adLeftHref +"\"><embed src=\"" + adLeftSrc + "\" quality=\"high\"  width=\"" + adLeftWidth + "\" height=\"" + adLeftHeight + "\" type=\"application/x-shockwave-flash\"></embed></a></div>");
    }
    else{
     document.write("<div id=\"adLeftFloat\" style=\"position: absolute;width:" + adLeftWidth + ";\"><a href=\"" + adLeftHref +"\"><img src=\"" + adLeftSrc + "\"  width=\"" + adLeftWidth + "\" height=\"" + adLeftHeight + "\"  border=\"0\" \></a></div>");
    }
   }
   if (adRightSrc != "") {
    if (adRightFlash == "flash") {
     document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + adRightWidth + ";\"><a href=\"" + adRightHref +"\"><embed src=\"" + adRightSrc + "\" quality=\"high\"  width=\"" + adLeftWidth + "\" height=\"" + adRightHeight + "\" type=\"application/x-shockwave-flash\"></a></embed></div>");
    }
    else{
     document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + adRightWidth + ";\"><a href=\"" + adRightHref +"\"><img src=\"" + adRightSrc + "\"   width=\"" + adLeftWidth + "\" height=\"" + adRightHeight + "\"  border=\"0\"  \></a></div>");
    }
   }
   load();
   //]]>

posted on 2006-05-11 09:58  kary  阅读(1629)  评论(0编辑  收藏  举报

导航