javascript - Get Jquery modal box to appear on page load -


i need jquery box appear on page load. right appears when user clicks link.

here trigger:

    <script type="text/javascript">   $(document).ready(function() {        //select tag name equal modal     $('a[name=modal]').click(function(e) {         //cancel link behavior         e.preventdefault();          //get tag         var id = $(this).attr('href');          //get screen height , width         var maskheight = $(document).height();         var maskwidth = $(window).width();          //set heigth , width mask fill whole screen         $('#mask').css({'width':maskwidth,'height':maskheight});          //transition effect              $('#mask').fadein(1000);             $('#mask').fadeto("slow",0.8);            //get window height , width         var winh = $(window).height();         var winw = $(window).width();          //set popup window center         $(id).css('top',  winh/2-$(id).height()/2);         $(id).css('left', winw/2-$(id).width()/2);          //transition effect         $(id).fadein(2000);       });      //if close button clicked     $('.window .close').click(function (e) {         //cancel link behavior         e.preventdefault();          $('#mask').hide();         $('.window').hide();     });           //if mask clicked     $('#mask').click(function () {         $(this).hide();         $('.window').hide();     });           });  </script>  

im sure there must sort of solution here, ideas?

you can fire click event on necessary link

$(window).load(function() {     $('a#initialmodallink[name=modal]').trigger("click"); }); 

where initialmodallink id of link should execute modal window. (and better) can extract modal window opening separate function , use it:

function openmodal(id) {      //get screen height , width     var maskheight = $(document).height();     var maskwidth = $(window).width();      //set heigth , width mask fill whole screen     $('#mask').css({'width':maskwidth,'height':maskheight});      //transition effect     $('#mask').fadein(1000);     $('#mask').fadeto("slow", 0.8);      //get window height , width     var winh = $(window).height();     var winw = $(window).width();      //set popup window center     $(id).css('top', winh / 2 - $(id).height() / 2);     $(id).css('left', winw / 2 - $(id).width() / 2);      //transition effect     $(id).fadein(2000);  }  $(document).ready(function() {      $('a[name=modal]').click(function(e) {         //cancel link behavior         e.preventdefault();         openmodal($(this).attr('href'));     });      openmodal('the href of initial modal box');  }); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -