-2
$(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();
    });     

});

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

4

2 回答 2

0

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

$(document).ready(function() {
  if (!$.cookie('showPopup')) {
    showPopup();
    $.cookie('showPopup', 'yes')
  }
});
于 2013-04-10T04:34:16.087 回答
0

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

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

}

于 2013-04-10T04:45:32.060 回答