Jim
Jim

Reputation: 407

How do I link to a modal dialog from an external link?

My website has a payment form in a modal. All I want is (for some specific customers) to pass them a link and when they click on it to move to the website with the modal already be open. Is that possible?

Upvotes: 2

Views: 5967

Answers (1)

davidkonrad
davidkonrad

Reputation: 85518

You must facilitate the feature yourself. Lets say you have normal bootstrap modal like this :

<div class="modal fade" id="payment">
  <div class="modal-dialog">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

and you want to invoke the modal on page load in a link sent to some users :

http://www.example.com#payment

Then add this code snippet to your page :

$(document).ready(function() {  
  var modals = ['#payment', '#anotherModal'];
  if (window.location.hash && ~modals.indexOf(window.location.hash)) {
     $(window.location.hash).modal();
  }
})

This is of course by far the most simple way to do it.

Upvotes: 4

Related Questions