弹出框只弹一次,看到网上也就写的很多,但真正能拿过来用的没有几个。以下是我修改之后的代码,供参考。 
这段代码是使用了cookie来控制的,首先使用cookie让浏览器记住这个页面已经打开过一次,如果再次引用这个页面已经打开一次了,如果再次引用这个页面的话将不进行打开。而浏览器一旦关闭浏览器,保存这个记录的cookie文件将被删除。因此关闭浏览器,再次打开的话弹出窗口还会出现的,从而确保了在原有的窗口基础上只打开一个窗口。 
复制代码 代码如下:
 
<script type="text/javascript"> 
var returnvalue = ""; 
function openpopup(){ 
<s:if test="isAlreadyGetGift == 0"> 
$.colorbox({inline:true, href:'#getGiftForm',innerWidth:'650px;',innerHeight:'475px;',onOpen:true}); 
$("#getGiftSuccess").hide(); 
</s:if> 
} 
function get_cookie(Name) { 
var search = Name + "="; 
if (document.cookie.length > 0) { 
offset = document.cookie.indexOf(search); 
if (offset != -1) { 
// if cookie exists 
offset += search.length; 
// set index of beginning of value 
end = document.cookie.indexOf(";", offset); 
// set index of end of cookie value 
if (end == 10){ 
end = document.cookie.length; 
returnvalue=unescape(document.cookie.substring(offset, end)); 
} 
} 
} 
return returnvalue; 
} 
function loadpopup(){ 
if (get_cookie("popped")==""){ 
openpopup(); 
document.cookie="popped=yes" 
} 
} 
$(document).ready(function(){ 
loadpopup(); 
}); 
</script> 
您可能感兴趣的文章:
