title: I want to show modal popup before leaving the page
body: <pre><code>&lt;a href="https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&amp;stacked=h" id="leave"&gt;click here to leave the page&lt;/a&gt;
  
  
  &lt;div id="myModal" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-dialog"&gt;
  
      &lt;!-- Modal content--&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
          &lt;h4 class="modal-title"&gt;Modal Header&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
          &lt;p&gt;Changes made may not be saved.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
    &lt;/div&gt;
  &lt;/div&gt;
  
  $("#leave").click(function() {
    $(window).bind('beforeunload', function() {
      return 'Changes you made may not be Saved';
    });
  });
  </code></pre>
  
  <p><a href="https://jsfiddle.net/vishagvj/qkbgzyhc/74/" rel="nofollow noreferrer">here is the js fiddle am working on </a></p>