每次刷新浏览器时都会打开onload弹出窗口

时间:2013-04-10 04:31:46

标签: 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();
    });     

});

我将此代码用于有载弹出框但是当我每次刷新浏览器时都不会显示此弹出框,请告诉我正确的方法。

2 个答案:

答案 0 :(得分:0)

您需要使用某种cookie来首次设置。因此,在添加jQuery.cookie插件后,将所有内容包装在函数中,例如showPopup();并以这种方式调用代码。

$(document).ready(function() {
  if (!$.cookie('showPopup')) {
    showPopup();
    $.cookie('showPopup', 'yes')
  }
});

答案 1 :(得分:0)

使用此事件设置任何变量,并在您的代码中使用它。

window.onunload = function(){
alert("unload event detected!");

}

相关问题