Modal window once a session with jQuery

泄露秘密 提交于 2019-12-13 12:50:40

问题


I'm looking for a script, preferably a jQuery plugin, to display a modal window when entering my website (whichever page) but only once during the same browsing session, so when the user closes and reopens the browser he sees the modal window again in my website. Can somebody help me? Thanks


回答1:


Use cookies ...

Look at http://plugins.jquery.com/files/jquery.cookie.js.txt

Do not use an expire value (so that the cookie is a session cookie)..

if ($.cookie('modal') != 'shown')
   {
     $.cookie('modal', 'shown');
     // code to show modal
   }



回答2:


I think the easiest solution would be to set a cookie (using javascript) and show the window, and the second time around have the javascript check the content of the cookie (let's say you just store a visit count in the cookie) and decide not to show the window.




回答3:


You could use a session cookie. There is a jquery cookie plugin available here.

In your pages you use document ready to check if the cookie exists, if not show the popup then create the cookie. The cookie would be destroyed when the user closes the browser.




回答4:


I dont see the point in cookies any more apart from server side scripting

If your using jQuery and grasping the latest Javascript Features then you should really go with HTML 5's Data Storage:

HTML5 Local Storage: http://dev.w3.org/html5/webstorage/ AND http://html5demos.com/storage

HTML5 Client Side SQL: http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage/

General HTML5: http://html5demos.com/




回答5:


Sorry for my late answer! I made what suggested by Gaby in conjunction with the jQuery Smart Modal script, it seems working perfectly. Thanks to all anyway



来源:https://stackoverflow.com/questions/3202944/modal-window-once-a-session-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!