Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - direct link to modal window

Is it possible to have an url like this:

www.url.com/#imprint
(or similar) to link directly to the page with the opened modal window?

is this possible? Any hints?
Thank you!

like image 957
Marek123 Avatar asked Dec 18 '13 15:12

Marek123


2 Answers

You might be able to do something like this.

if (window.location.hash == "#imprint") {
     $('#myModal').modal('show');
}
like image 157
Jako Avatar answered Oct 01 '22 07:10

Jako


Just for future visitors/readers, I have created a very simple function to open a modal dynamically without the need to know the exact ID that you're looking for. It just falls through if no hash is located.

/**
 * Function to open a bootstrap modal based on ID
 * @param int
 */
function directLinkModal(hash) {
  $(hash).modal('show');
}

/**
 * Call the function on window load
 * @param hash of the window
 */
directLinkModal(window.location.hash);
like image 32
camelCase Avatar answered Oct 01 '22 09:10

camelCase