tags:

views:

113

answers:

5

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

+2  A: 

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
   }
Gaby
beat me to it by a couple of seconds, +1 :)
roe
A: 

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.

roe
A: 

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.

redsquare
A: 

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/

RobertPitt
robert - yes and no. html5 isn't prevelant enough in the marketplace yet to warrent this approach. it's certainly a 'good' appraoch technically but when you review the stats and see the sad fact that IE6 is STILL accounting for over 7% of the audeince, then you're going to have a high faliure rate or at the very least, a lot of conditional coding to do.just my thoughts...
jim
Thats true and because of the OP's skill level, he would not really understand fully how tio implement fall backs for IE6 Browsers, but yea i agree, its a Yes and No issue.
RobertPitt
A: 

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

Urbini