开发者

Modal window once a session with jQuery

开发者 https://www.devze.com 2023-01-05 23:12 出处:网络
I\'m looking for a script, preferably a jQuery plugin, to display a modal window when entering my website (whichever page) bu开发者_Python百科t only once during the same browsing session, so when the

I'm looking for a script, preferably a jQuery plugin, to display a modal window when entering my website (whichever page) bu开发者_Python百科t 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


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
   }


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.


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.


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/


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

0

精彩评论

暂无评论...
验证码 换一张
取 消