2016-07-24 31 views
2

我知道这个问题问了好几次,我做了一个小小的研究,并添加了我的代码,还在某处我做错了,现在对我来说。以下指出我需要达到的目标。 1.打开主页上的弹出窗口。 2. Popup应该位于所有浏览器的中心。 3.弹出窗口应淡入。 4.应该只对一个用户打开一次。在bigcommerce中打开Popup一次

这是我的测试网站http://popuptest.mybigcommerce.com/

到目前为止弹出开放,对我来说,在弹出中心,并期待淡入工作。但会话不工作。

下面是我工作

index.html中

<div id="boxes"> 
    <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> 
     <img src="images/coupon2011.jpg" width="507" height="300" /> 
    <a href="#" class="close"><img src="images/closelabel.gif" width="66" height="22" /></a> 
</div> 
<!-- Mask to cover the whole screen --> 
<div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div> 
</div> 
在htmlhead.html

现在使用的代码,下面的代码。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 

    var id = '#dialog'; 

    //Get the screen height and width 
    var maskHeight = $(document).height(); 
    var maskWidth = $(window).width(); 

    //Set heigth and width to mask to fill up the whole screen 
    $('#mask').css({'width':maskWidth,'height':maskHeight}); 

    //transition effect  
    $('#mask').fadeIn(1000);  
    $('#mask').fadeTo("slow",0.8); 

    //Get the window height and width 
    var winH = $(window).height(); 
    var winW = $(window).width(); 

    //Set the popup window to center 
    $(id).css('top', winH/2-$(id).height()/2); 
    $(id).css('left', winW/2-$(id).width()/2); 

    //transition effect 
    $(id).fadeIn(2000);  

//if close button is clicked 
$('.window .close').click(function (e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    $('#mask').hide(); 
    $('.window').hide(); 
    });  

//if mask is clicked 
$('#mask').click(function() { 
    $(this).hide(); 
    $('.window').hide(); 
});  

}); 

</script> 

<script type="text/javascript"> 

var once_per_session=1 

function get_cookie(Name) { 
var search = Name + "=" 
var returnvalue = ""; 
if (document.cookie.length > 0) { 
offset = document.cookie.indexOf(search) 
if (offset != -1) { // if cookie exists 
offset += search.length 
end = document.cookie.indexOf(";", offset); 
if (end == -1) 
end = document.cookie.length; 
returnvalue=unescape(document.cookie.substring(offset, end)) 
} 
} 
return returnvalue; 
} 

function loadpopunder(){ 
if (get_cookie('popunder')==''){ 
loadpopunder() 
document.cookie="popunder=yes" 
} 
} 
function loadpopunder(){ 
if (once_per_session==0) 
loadpopunder() 
else 
{ 
if (get_cookie('popunder')==''){ 
loadpopunder() 
document.cookie="popunder=yes" 
} 
} 
} 
</script> 

任何建议或教程将是伟大的完成。

+0

我注意到,当你说“弹出”和“隐藏弹出式”它看起来像你只是实施模态对话。这种性质的真正弹出窗口现在已被主流浏览器的弹出式窗口拦截器阻止。 – ceejayoz

回答

1

您可以使用JavaScript库js-cookie。借助此库,您可以轻松设置并获取Cookie。

如果你使用JS-饼干您htmlhead.html代码应该是这个样子:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    // Check if cookie exists 
    if (Cookies.get('popunder')) { 
     return; 
    } 

    var id = '#dialog'; 

    //Get the screen height and width 
    var maskHeight = $(document).height(); 
    var maskWidth = $(window).width(); 

    //Set heigth and width to mask to fill up the whole screen 
    $('#mask').css({'width':maskWidth,'height':maskHeight}); 

    //transition effect  
    $('#mask').fadeIn(1000);  
    $('#mask').fadeTo("slow",0.8); 

    //Get the window height and width 
    var winH = $(window).height(); 
    var winW = $(window).width(); 

    //Set the popup window to center 
    $(id).css('top', winH/2-$(id).height()/2); 
    $(id).css('left', winW/2-$(id).width()/2); 

    //transition effect 
    $(id).fadeIn(2000);  

    // Set cookie to be sure the popover activated again 
    Cookies.set('popunder', '1'); 

    //if close button is clicked 
    $('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $('#mask').hide(); 
     $('.window').hide(); 
    });  

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    });  

}); 

</script> 
+0

它的工作....... – user2829218