把以下代码存在一个js里
在需要弹出广告的页面加入如下代码:
在<head></head>中调用JS文件
window.onload = getMsg;
window.onresize = resizeDiv;
window.onerror = function(){}
//短信提示使用(FHB添加)
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
function getMsg()
{
try{
divTop = parseInt(document.getElementById("eMeng").style.top,10)
divLeft = parseInt(document.getElementById("eMeng").style.left,10)
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
document.getElementById("eMeng").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth
document.getElementById("eMeng").style.visibility="visible"
objTimer = window.setInterval("moveDiv()",10)
}
catch(e){}
}
function resizeDiv()
{
i+=1
//if(i>300) closeDiv() //想不用自动消失由用户来自己关闭就屏蔽这句
try{
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
}
catch(e){}
}
function moveDiv()
{
try
{
if(parseInt(document.getElementById("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
{
window.clearInterval(objTimer)
objTimer = window.setInterval("resizeDiv()",1)
}
divTop = parseInt(document.getElementById("eMeng").style.top,10)
document.getElementById("eMeng").style.top = divTop - 1
}
catch(e){}
}
function closeDiv()
{
document.getElementById('eMeng').style.visibility='hidden';
if(objTimer) window.clearInterval(objTimer)
}
window.onresize = resizeDiv;
window.onerror = function(){}
//短信提示使用(FHB添加)
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
function getMsg()
{
try{
divTop = parseInt(document.getElementById("eMeng").style.top,10)
divLeft = parseInt(document.getElementById("eMeng").style.left,10)
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
document.getElementById("eMeng").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth
document.getElementById("eMeng").style.visibility="visible"
objTimer = window.setInterval("moveDiv()",10)
}
catch(e){}
}
function resizeDiv()
{
i+=1
//if(i>300) closeDiv() //想不用自动消失由用户来自己关闭就屏蔽这句
try{
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
}
catch(e){}
}
function moveDiv()
{
try
{
if(parseInt(document.getElementById("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
{
window.clearInterval(objTimer)
objTimer = window.setInterval("resizeDiv()",1)
}
divTop = parseInt(document.getElementById("eMeng").style.top,10)
document.getElementById("eMeng").style.top = divTop - 1
}
catch(e){}
}
function closeDiv()
{
document.getElementById('eMeng').style.visibility='hidden';
if(objTimer) window.clearInterval(objTimer)
}
在需要弹出广告的页面加入如下代码:
<div id="eMeng" style="border-right: #455690 1px solid; border-top: #a6b4cf 1px solid;
z-index: 99999; left: 0px; visibility: hidden; border-left: #a6b4cf 1px solid;
width: 180px; border-bottom: #455690 1px solid; position: absolute; top: 0px;
height: 116px; background-color: #c9d3f3">
<table style="border-top: #ffffff 1px solid; border-left: #ffffff 1px solid" cellspacing="0"
cellpadding="0" width="100%" bgcolor="#AFDCF3" border="0">
<tbody>
<tr bgcolor="#6699cc">
<td valign="center" width="100%" style="vertical-align: middle; height: 24px; background-color: #ff0066; text-align: center">
**网提示:</td>
<td style="background-image: url('msgTopBg.gif'); padding-right: 2px; padding-top: 2px; height: 24px;"
valign="center" align="right" width="19">
<span title="关闭" onclick="closeDiv()">×</span><!--<IMG title=关闭 style="CURSOR: hand" onclick=closeDiv() hspace=3 src="msgClose.jpg">--></td>
</tr>
<tr>
<td style="background-image: url('/UploadFiles/200510822587734.jpg'); padding-right: 1px;
padding-bottom: 1px; width: 183px;" colspan="3" height="90">
<div style="border-right: #b9c9ef 1px solid; padding-right: 13px; border-top: #728eb8 1px solid;
padding-left: 13px; font-size: 12px; padding-bottom: 13px; border-left: #728eb8 1px solid;
width: 100%; color: #1f336b; padding-top: 18px; border-bottom: #b9c9ef 1px solid;
height: 100%">
**<br>
<br>
<div align="center" style="word-break: break-all">
<a href="#" target="_blank"><font color="#FF0000">进入**论坛</font></a></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
z-index: 99999; left: 0px; visibility: hidden; border-left: #a6b4cf 1px solid;
width: 180px; border-bottom: #455690 1px solid; position: absolute; top: 0px;
height: 116px; background-color: #c9d3f3">
<table style="border-top: #ffffff 1px solid; border-left: #ffffff 1px solid" cellspacing="0"
cellpadding="0" width="100%" bgcolor="#AFDCF3" border="0">
<tbody>
<tr bgcolor="#6699cc">
<td valign="center" width="100%" style="vertical-align: middle; height: 24px; background-color: #ff0066; text-align: center">
**网提示:</td>
<td style="background-image: url('msgTopBg.gif'); padding-right: 2px; padding-top: 2px; height: 24px;"
valign="center" align="right" width="19">
<span title="关闭" onclick="closeDiv()">×</span><!--<IMG title=关闭 style="CURSOR: hand" onclick=closeDiv() hspace=3 src="msgClose.jpg">--></td>
</tr>
<tr>
<td style="background-image: url('/UploadFiles/200510822587734.jpg'); padding-right: 1px;
padding-bottom: 1px; width: 183px;" colspan="3" height="90">
<div style="border-right: #b9c9ef 1px solid; padding-right: 13px; border-top: #728eb8 1px solid;
padding-left: 13px; font-size: 12px; padding-bottom: 13px; border-left: #728eb8 1px solid;
width: 100%; color: #1f336b; padding-top: 18px; border-bottom: #b9c9ef 1px solid;
height: 100%">
**<br>
<br>
<div align="center" style="word-break: break-all">
<a href="#" target="_blank"><font color="#FF0000">进入**论坛</font></a></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
在<head></head>中调用JS文件
来源:https://www.cnblogs.com/liufeng/archive/2007/11/27/974168.html