JS广告代码

JavaScript011

JS广告代码,第1张

在网页中要放图片的位置加入这一段代码:

<script language="javascript" src="ad.js"></script>

ad.js内容如下:

//广告图片

var mqycn_ad_img="img/ad.gif"

//广告连接

var mqycn_ad_href="http://hi.baidu.com/mqycn"

var mqycn_outhtml

mqycn_outhtml="<a href=\""+mqycn_ad_href+"\" target=\"_blank\">"

mqycn_outhtml+="<img src=\""+mqycn_ad_img+"\" width=\"468\" height=\"60\" style=\"border:none\"></a>"

document.write(mqycn_outhtml)

可以遮挡ie6下的select元素 但是在ie6下div没有透明度;

弹出的div可以一直在浏览器屏幕中间显示 。

代码:

var _CalF = { //便捷方法

$ : function(id){return document.getElementById(id)},

create : function(id){return document.createElement(id)},

append : function(id){return document.body.appendChild(id)},

remove : function(id){return document.body.removeChild(id)}

}

function popup(openID,conID,closeID){

this.onclick(openID,conID,closeID)

}

popup.prototype = {

cssStyle : "width:100%position:absoluteleft:0top:0filter:alpha(opacity = 50)opacity:0.5border:0overflow:auto",

createShadowDiv : function(){ //背景遮罩

var shadowDiv = _CalF.create("div")

shadowDiv.id = "shadowDiv"

shadowDiv.style.cssText = this.cssStyle

shadowDiv.style.height = document.body.scrollHeight + "px"

shadowDiv.style.backgroundColor = "#000"

shadowDiv.style.zindex = 100

_CalF.append(shadowDiv)

},

createIframe : function(){ //iframe

var iframe = _CalF.create("iframe")

iframe.id = "shadowIframe"

iframe.style.cssText = this.cssStyle

iframe.style.height = document.body.scrollHeight + "px"

iframe.style.zindex = 99

_CalF.append(iframe)

},

removeDiv : function(){

_CalF.remove(_CalF.$("shadowDiv"))

_CalF.remove(_CalF.$("shadowIframe"))

},

onclick : function(openID,conID,closeID){

var that = this

_CalF.$(openID).onclick = function(){

if(window.ActiveXObject){ //ie6

if(!window.XMLHttpRequest){

document.body.style.cssText = "_background-image: url(about:blank)_background-attachment: fixed"

}

}

that.createIframe()

that.createShadowDiv()

_CalF.$(conID).style.display = "block"

}

document.getElementById(closeID).onclick = function(){

_CalF.$(conID).style.display = "none"

that.removeDiv()

}

}

}

var bt = new popup("bt","orderMsg","close")

</script>

</body>

</html>