如何在jQuery中设置会话变量? [英] How to set session variable in jquery?

查看:72
本文介绍了如何在jQuery中设置会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只需要在第一次打开页面时设置弹出窗口。我认为会话或cookie将被设置。

 < script> 
!window.jQuery&& document.write('< script src =fancybox / jquery-1.4.3.min.js>< \ / script>');
< / script>
< script type =text / javascriptsrc =fancybox / jquery.fancybox-1.3.4.pack.js>< / script>
< script type =text / javascript>
$(文件)。就绪(函数(){
$( A#示例1)的fancybox();
$( A#示例1)的触发器( '点击' );
});

< / script>
将链接的rel = 样式表 类型= 文本/ CSS的 href = 的fancybox / jquery.fancybox-1.3.4.css 媒体= 屏幕/>
< / head>
< body>
< a id =example1href =images / pic.jpg>< / a>
< / body>


解决方案

使用 localStorage 来存储您打开该页面的事实:

  $(document).ready(function(){
var yetVisited = localStorage ['visited'];
if(!yetVisited){
// open popup
localStorage [ 'visited'] =是;
}
});


I have an html page that open a popup window when the page loads.

I need to set the popup only when the page open first time. I think session or cookie is to be set.

    <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>

解决方案

Use localStorage to store the fact that you opened the page :

$(document).ready(function() {
    var yetVisited = localStorage['visited'];
    if (!yetVisited) {
        // open popup
        localStorage['visited'] = "yes";
    }
});

这篇关于如何在jQuery中设置会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆