简体   繁体   English

如何仅在首次加载页面时设置弹出窗口?

[英]How to set popup on page load first time only?

How to set a popup window that open when first time the page load? 如何设置第一次加载页面时打开的弹出窗口? im using this code for my popup how to set session for this popup? 即时通讯使用此代码为我的弹出窗口如何设置此弹出窗口的会话? is there any way to use ip as session? 有什么方法可以将IP用作会话?

    <script>
        !window.jQuery && document.write('<script src="fancybox/jquery-1.4.3.min.js"><\/script>');
    </script>

    <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.pack.js"></script>   

    <script type="text/javascript">

    $(document).ready(function() {


        $("a#example1").fancybox();

        $("a#example1").trigger('click');


    });
    </script>


    <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.4.css" media="screen" />


</head>



<body>

<a id="example1" href="images/pic.jpg"></a> 



</body>

Check for a cookie, and if not there, do the popup and set the cookie for next time; 检查cookie,如果不存在,则执行弹出窗口并设置下次cookie。 if the cookie is there, don't do the popup. 如果有cookie,请不要执行弹出窗口。 Quirksmode has some functions for making cookies easier, or of course there's the jQuery cookie plugin (and probably about 50 others). Quirksmode具有一些使cookie变得更容易的功能 ,或者当然有jQuery cookie插件 (可能还有大约50个)。

you can use jquery-cookie 您可以使用jquery-cookie

Demo : 演示:

$(document).ready(function() {
       if($.cookie('popup') != 1){
           $.cookie('popup', '1');
           $("a#example1").fancybox();
           $("a#example1").trigger('click');
        }
    });

Using sessions for this would be an unnecessary load on your server. 为此使用会话将是服务器上不必要的负载。 Use cookies instead, that helps to store data in the user's computer. 改用cookie,这有助于将数据存储在用户的计算机中。

Use Javascript/your server language to check the cookie and show the popup based on its value! 使用Javascript /您的服务器语言检查Cookie,并根据其值显示弹出窗口!

You can you Cookies or localStorage Using Cookies: 您可以使用Cookies来使用Cookies或localStorage:

$(document).ready(function() {
var loadfirst = getCookie("loadfirsttime");
if(loadfirst == null){
setCookie("loadfirst", "again" 1); // 1 is the number of days
$("a#example1").fancybox();
 $("a#example1").trigger('click');
}
});

Using LocalStorage: 使用LocalStorage:

$(document).ready(function() {
 var loadfirst = localStorage.getItem("loadfirsttime");
if(loadfirst == null){
localStorage.setItem('loadfirst ', 1); // 1 is value assigned.
$("a#example1").fancybox();
 $("a#example1").trigger('click');
}
});

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM