2

I'm using this to display my modal.

<script>
        Mousetrap.bind('j e f f r e y enter', function() {
            $('#myModal').modal('show')
        });              
</script>

Normally a button is used.

<a data-toggle="modal" class="btn btn-info" href="remote.html" data-target="#myModal">Click me !</a>

Is there any way to get the modal from another html page and call it using javascript?

Jeffrey Nerona
  • 135
  • 1
  • 10

1 Answers1

0

You can send an Ajax request to get the HTML code for modal, then append it to the document.

<script>
    var $modal = undefined;
    Mousetrap.bind('j e f f r e y enter', function() {
        if($modal === undefined)
        {
            $.get('path/to/modal.html', function(data)){
                if($modal === undefined)
                {
                      $modal = $(data);
                      $('body').append($modal);
                }
                $modal.modal('show');
            });
            return;
         }
         $modal.modal('show')
    });              
</script>
Momo
  • 321
  • 2
  • 4
  • 10