简体   繁体   中英

load external js file into bootstrap modal box

I need to show google map in bootstrap modal box. I load google map API from google site in my page and modal box worked. Like This :

<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script>

HTML :

<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>

Now, I need to load google map api( .JS File / Libraries ) from url after click link (launch Modal) of modal box. How to create this ?

If you're using jQuery, then you could use the jQuery.getScript() method: http://api.jquery.com/jquery.getscript/

Basic usage:

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM