javascript - Popup on website load once per session -


this question has answer here:

i found ways make javascript/jquery popup windows. but, there problems, first of all, not these 2 languages, beginner.

if there ready code, opening popup window on website load, once per browser session. nice, if me this.

i need simple popup, text in it, design popup box looking, not original browser popup (like in image), of course, closing button.

http://i.stack.imgur.com/xnwxf.png

thanks lot

i know shouldn't , provide answer without trying attempt first because won't learning way.

but i'm feeling nice today, i'm providing of way of doing pop on first load , not loading pop again until session been destroyed.

you need set session, when load page doing following:

sessionstorage.setitem('firstvisit', '1'); 

then need check session this:

if there no session called firstvisit show message box

    if (!sessionstorage.getitem('firstvisit') === "1")     {        $(".message").show();      }  

example

html

<div class="message">     <div class="message_pad">         <div id="message"></div>         <div class="message_leave">          </div>     </div> </div> 

javascript/jquery

// save data sessionstorage sessionstorage.setitem('firstvisit', '1');  /* fix size on document ready.*/ $(function() {     if (!sessionstorage.getitem('firstvisit') === "1")     {        $(".message").show();      }       //close element.     $(".message").click(function()     {        $(this).hide();     });      $(".message").css({         'height': $(document).height()+'px'     });     $(".message_pad").css({         'left': ($(document).width()/2 - 500/2)+'px'     }); }); /* * fix size on resize. */ $(window).resize(function(){     $(".message").css({         'height': $(document).height()+'px'     });     $(".message_pad").css({         'left': ($(document).width()/2 - 500/2)+'px'     }); }); 

jsfiddle


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -