Question

Is there a way to have it so that if I go to for example: http://www.example.org/modal.html?openmodal=true the modal will open onLoad but if I go to http://www.example.org/modal.html the modal won't open onload?

Was it helpful?

Solution

http://getbootstrap.com/javascript/#modals tells you $('#myModal').modal('show') opens a window manually. So with your modal got id="myModal", try this:

//from: https://stackoverflow.com/questions/3788125/jquery-querystring  
function querystring(key) {
   var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
   var r=[], m;
   while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
   return r;
}
var querystring = querystring('modal');
if (querystring.length && querystring[0]==='true' ) {$('#myModal').modal('show');}

This will open the modal when ?modal=true is has been set.

Reference: jQuery querystring

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top