彈出框只彈一次,看到網上也就寫的很多,但真正能拿過來用的沒有幾個。以下是我修改之后的代碼,供參考。 
這段代碼是使用了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> 
新聞熱點
疑難解答
圖片精選