Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open modal with # in url

Im sorry for this probably dumm question, but I want to simply open modals with # in the url. So if i call www.domain.com/#modal1 it will open the page with the modal poped-up already.

Oh Im using jquery.

Thank you!

like image 650
Tomas Avatar asked Apr 05 '12 04:04

Tomas


People also ask

What does open in modal mean?

A modal (also called a modal window or lightbox) is a web page element that displays in front of and deactivates all other page content. To return to the main content, the user must engage with the modal by completing an action or by closing it.

How do you open a modal with a tag?

You can display bootstrap modal using data attribute (data-toggle, data-target) in anchor tag. You have to use bootstrap CDN in your HTML page in which you want to use the bootstrap modal.

How do you open and close modals?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

How do I open a modal file?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.


1 Answers

Many application frameworks (I'm partial to backbone) use some kind of router to accomplish this, but you could fake your own by checking window.hash and running an appropriate function:

function popModal() {
  // code to pop up modal dialog
}

var hash = window.location.hash;
if (hash.substring(1) == 'modal1') {
  popModal();
}

​​

like image 108
rjz Avatar answered Sep 20 '22 04:09

rjz