How to open external URL in bootstrap modal?

3

I already use the bootstrap modal and it worked very well for the content I tested. But I can not find anything that explains how to open an external page in a modal on the site. Does anyone know how to do it? I'm grateful for the help!

    
asked by anonymous 03.04.2017 / 17:55

1 answer

2
<a data-toggle="modal" class="btn" href="http://www.bing.com" data-target="#myModal">click me</a>


<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
  </div>
</div>

Javascript:

$('a.btn').on('click', function(e) {
    e.preventDefault();
    var url = $(this).attr('href');
    $(".modal-body").html('<iframe width="100%" height="100%" frameborder="0" scrolling="yes" allowtransparency="true" src="'+url+'"></iframe>');
});

In case you will have to use an iframe see working in jsfidle: link

    
03.04.2017 / 18:29