首页 > 精选文章 > HTML&CSS > 正文

只弹一次的代码

经常会碰到这个问题,因此我整理了以下两钟较简单的方法:

如何让弹窗只弹一次:

1.使用asp控制一个会话只弹一次:

<%
if session("ad")<>1 then
%>
<script language=javascript>
function pop_ad(){ 
window.open('http://www.itlearner.com','窗口ID','scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes,width=300,height=300');  

setTimeout(pop_ad(),3000);
</script>
<%
session("ad")=1
end if
%> 

2.使用js用cookies方式控制只弹出一次窗口

<script language="javascript">
<!--
function openpopup(){
window.open('http://www.itlearner.com','itlearner',width=300,height=300,left=0,top=0)
}

function GetCookie (name) {
var search = name + "=";
var returnvalue = null;
if (documents.cookie.length > 0) {
offset = documents.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents.cookie.indexOf(";",offset);
if (end == -1)
end = documents.cookie.length;
returnvalue=unescape(documents.cookie.substring(offset, end))
}
}
return returnvalue;
}

function pop_ad(){
if (GetCookie('popped')==null||GetCookie('popped')==''){
documents.cookie='popped=yes';
openpopup();
}
}
pop_ad();
//-->
</script>

  • 上一篇:为什么不能用炸药炸厦门人?
  • 下一篇:Windows下权限设置详解
  • 了解这些字:只的意思 弹的意思 一的意思 次的意思 的的意思 代的意思 码的意思