Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use external(http) library in a JS file [duplicate]

Tags:

javascript

I have found several answers about this but in my undestanding they cover libraries located in same dir with calling file.

In my application, I currently have the following code inside index.html page head:

<script type="text/javascript"
          src="https://apis.google.com/js/api.js"></script>

What I want to do is load and use the same library inside a .js file. The application is client-side and is currently using the following frameworks: "serveup", "hem","es5-shimify", "json2ify", jqueryify".

I have tried using jquery 'require' but I got error message saying the module was not found, I am guessing it was looking for a local file.

like image 404
Giannis Avatar asked Oct 24 '25 18:10

Giannis


1 Answers

Try this:

  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", "https://apis.google.com/js/api.js");
like image 177
matt2000 Avatar answered Oct 26 '25 08:10

matt2000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!