Non-standard question - is it possible to control the display of a modal window through the address bar? that is, For example, there is site.ru and 2 windows - # modal1 # modal2 standard call modal window

<button data-target="#modal1" data-toggle="modal" class="btn btn-info btn-md">Модальное окно 1</button> 

so that for example by going to site.ru/?q=#modal1 the site opened with the window already shown # modal1 site in pure HTML

  • connected jQuery Bootstrap - Igor Fostiak
  • What comes after the '#' is not transmitted to the server. Therefore, in pure HTML it will not work, you must use js. - Arnial
  • @Arnial can poke your nose in an example? jQuery and Bootstrap are connected to the site - Igor Fostyak
  • It will take pure js :) by document ready check that in the address bar and initiate a popup as needed - jekaby
  • @jekaby poke your nose in examples please) I'm in JS almost 0 - Igor Fostyak

2 answers 2

If you want to go this way, it is best to intercept the address bar via javascript (jquery). This can be done like this:

 window.location.href // вся строка window.location.hash // то, что после # 

Respectively:

 $(document).ready(function(){ var url = window.location.href; var hash = window.location.hash; // http://example.com - url // http://example.com#modal - hash if(hash == '#modal'){ $('.modal').show('slow'); } }); 

Something like this.

  • Thanks a lot! - Igor Fostyak
  • @ Igor Fostyak Please. Instead of thanks, you can still mark the answer as the best) - Rosnowsky
 $ (document) .ready (function () {
     var ancor = window.location.hash.replace ("#", "");
     if (ancor == 'modal1') {
         $ ('# modal1'). modal ('show');
     }
 }
  • Thanks a lot! - Igor Fostyak
  • one
    it's easier right away - $('#'+ancor).modal('show') - Artem Gorlachev