2012-10-18 56 views
0

嗨我試圖創建一個cookie後彈出窗口顯示在頁面加載,但不知何故彈出窗口仍然顯示,因爲在我看來,餅乾不創建。有人可以告訴我爲什麼會發生這種情況,我的錯誤在哪裏?jquery popup總是顯示

因此,這裏是我的popup.js文件內容

//SETTING UP OUR POPUP 
//0 means disabled; 1 means enabled; 
var popupStatus = 0; 

//loading popup with jQuery magic! 
function loadPopup(){ 
    //loads popup only if it is disabled 
    if(popupStatus==0){ 
     $("#backgroundPopup").css({ 
      "opacity": "0.7" 
     }); 
     $("#backgroundPopup").fadeIn("slow"); 
     $("#popupContact").fadeIn("slow"); 
     popupStatus = 1; 
    } 
} 

//disabling popup with jQuery magic! 
function disablePopup(){ 
    //disables popup only if it is enabled 
    if(popupStatus==1){ 
     $("#backgroundPopup").fadeOut("slow"); 
     $("#popupContact").fadeOut("slow"); 
     popupStatus = 0; 
    } 
} 

//centering popup 
function centerPopup(){ 
    //request data for centering 
    var windowWidth = document.documentElement.clientWidth; 
    var windowHeight = document.documentElement.clientHeight; 
    var popupHeight = $("#popupContact").height(); 
    var popupWidth = $("#popupContact").width(); 
    //centering 
    $("#popupContact").css({ 
     "position": "absolute", 
     "top": windowHeight/2-popupHeight/2, 
     "left": windowWidth/2-popupWidth/2 
    }); 
    //only need force for IE6 

    $("#backgroundPopup").css({ 
     "height": windowHeight 
    }); 

} 
//---------------cookies-------------------// 

function getCookie(c_name) 
{ 
var i,x,y,ARRcookies=document.cookie.split(";"); 
for (i=0;i<ARRcookies.length;i++) 
    { 
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); 
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); 
    x=x.replace(/^\s+|\s+$/g,""); 
    if (x==c_name) 
    { 
    return unescape(y); 
    } 
    } 
} 

function setCookie(c_name,value,exdays) 
{ 
var exdate=new Date(); 
exdate.setDate(exdate.getDate() + exdays); 
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); 
alert(c_value); 
document.cookie=c_name + "=" + c_value; 
} 

function checkCookie() 
{ 
var username=getCookie("shoppingKatalog"); 
if (username!=null && username!="") 
    { 
    alert(username); 
    } 
else 
    { 
    //centering with css 
    centerPopup(); 
    //load popup 
    loadPopup();  
    setCookie("shoppingKatalog","istekuva-za-eden-den",321); 
    } 
} 

//--------------end cookies---------------// 


//CONTROLLING EVENTS IN jQuery 
$(document).ready(function(){ 

    checkCookie(); 
    //LOADING POPUP 
    //Click the button event! 
    $("#button").click(function(){ 
     //centering with css 
     centerPopup(); 
     //load popup 
     loadPopup(); 
    }); 

    //CLOSING POPUP 
    //Click the x event! 
    $("#popupContactClose").click(function(){ 
     disablePopup(); 
    }); 
    //Click out event! 
    $("#backgroundPopup").click(function(){ 
     disablePopup(); 
    }); 
    //Press Escape event! 
    $(document).keypress(function(e){ 
     if(e.keyCode==27 && popupStatus==1){ 
      disablePopup(); 
     } 
    }); 

}); 

和我的index.html文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>yensdesign.com - How to create a stuning and smooth popup in jQuery</title> 
    <link rel="stylesheet" href="http://www.mywebsite.com/templates/it_theshop/popup/general.css" type="text/css" media="screen" /> 
    <script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script> 
    <script src="http://www.mywebsite.com/templates/it_theshop/popup/popup.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
    </script> 
</head> 
<body> 

    <center> 
     <a href="http://www.yensdesign.com"><img src="logo.jpg" alt="Go to yensdesign.com"/></a> 
    </center> 
    <div id="popupContact"> 
     <div id="popup_wrap" style="background-image:url('http://www.mywebsite.com/templates/it_theshop/images/popup/shopping-popup1.jpg');height:380px;width:800px;"> 
<div style="float:left;width:490px;padding:5px;"> 
<h1 style="margin:0px;">Заштеди до <span style="color:#981A32;">90%</span></h1> 
<h2 style="margin:0px;">Имајте ја информацијата - <span style="color:#981A32;">ПРВИ!</span></h2> 
<p style="margin:0px;">Дознај каде може да добиеш огромен попуст на чевли, облека, накит, козметика, производи за дома, услуги, патувања... Се она што го плаќаш во секојдневниот живот.</p> 
<h4 style="margin:0px;">Нашиот Newsletter е БЕСПЛАТЕН!</h4> 
<form method="post"> 

<table class="acymailing_form"> 
<p style="color:#981A32;margin:0px;">Одберете ја типот на информација што сакате да ја добивате:</p> 
<tr> 
<td align="left"><input type="checkbox" class="acymailing_checkbox" name="subscription[]" checked="checked" value="1" /><b style="color:#981A32;">СИТЕ ПОПУСТИ И ПРОИЗВОДИ</b></td> 
</tr> 
<tr> 
<td align="left"><input type="checkbox" class="acymailing_checkbox" name="subscription[]" value="2" /> 
<b style="color:#981A32;">САМО НОВИ ПРОИЗВОДИ</b></td> 
</tr> 
<tr> 
<td align="left"><input type="checkbox" class="acymailing_checkbox" name="subscription[]" value="4" /><b style="color:#981A32;">САМО ПОПУСТИ</b></td> 
</tr> 
<tr style="color:#981A32;"> 
<td><label for="user_name">Име</label><input id="user_name" type="text" name="user[name]" value="" /></td> 
</tr> 
<tr> 
<td style="color:#981A32;"><label for="user_email">E-мејл</label><input id="user_email" type="text" name="user[email]" value="" /></td> 
</tr> 
<tr> 
<td><div style="display:none;"><label for="user_html">Добивај</label></div></td> 
<td><div style="display:none;"><input type="radio" name="user[html]" value="0" id="user_html_0" /><label for="user_html_0">Text</label></div><div style="display:none;"><input type="radio" name="user[html]" value="1" id="user_html_1" checked="checked" /><label for="user_html_1">HTML</label></div></td> 
</tr> 

<tr> 
<td colspan="2"> 
<div style="display:none;"> 
<input type="radio" name="task" value="optin" checked="checked" id="optin" /><label for="optin">Subscribe</label> 
<input type="radio" name="task" value="optout" id="opftout" /><label for="optout">Unsubscribe</label> </div> 
<input class="button" type="submit" value="Пријави се БЕСПЛАТНО!" name="Submit" style="color: white;background-color: orange;border: 0;border-radius: 5px;height: 30px;font-weight: bold;margin-top:5px;" onclick="setCookie('mywebsite','istekuva-za-godina',364);" /></td> 
</tr> 
</table> 
<input type="hidden" name="gtask" value="sub" style="color:#981A32;" /> 
<input type="hidden" name="redirect" value="http://www.mywebsite.com" /> 
<input type="hidden" name="option" value="com_acymailing" /> 
<input type="hidden" name="visiblelists" value="1,2,4" /> 
<input type="hidden" name="hiddenlists" value="YOUR_LISTS" /> 
</form> 
</div> 
<img src="http://www.mywebsite.com/templates/it_theshop/images/popup/popust.png" style="float:right;padding-right:-10px;position: absolute;margin-left: 260px;" /> 
</div> 
    </div> 
    <div id="backgroundPopup"></div> 
</body> 
</html> 
+0

你確定'http://www.mywebsite.com/ templates/it_theshop/popup/popup.js'沒有關於這個報告的錯誤嗎?它是100%固體? –

+0

@BerkerYüceer這是我自己的文件 – Darko

+0

我可以看到,這就是爲什麼我問你確定你的js文件工作正常.. –

回答

0

您的Cookie已創建。因爲在你的函數checkCookie()中你使用的是

if (username!=null && username!="") 
{ 
alert(username); 
} 

這裏的條件不等於null。所以這個cookie被創建了

0

的彈出窗口顯示,因爲它不會被默認隱藏。儘量保持它隱藏的CSS:

#backgroundPopup { display:none } 

這應該隱藏它,然後在需要時顯示它。

+0

它的隱藏,參數是在我沒有包括的css文件中 – Darko

+0

您正在使用哪個瀏覽器? –

+0

鉻和火狐 – Darko