首页 > 设计 > WEB开发 > 正文

只弹一次的代码

2020-10-03 17:39:17
字体:
来源:转载
供稿:网友

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

如何让弹窗只弹一次:

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

<%
if session("ad")<>1 then
%>
<script language=javascript>
function pop_ad(){ 
window.open('http://www.CuoXin.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.CuoXin.com','CuoXin',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>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表