26

I know how to include CDN in HTML file.

<!DOCTYPE html>
<html>
<head>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
</body>
</html>

But what I am trying to do is:
I want to include CDN like jquery in my javascript file.

May be what I am trying to do is impossible.
Actually, I want to call BootstrapDialog.Confirm from my javascript file.
So, I want to include required CDN for BootstrapDialog in js file.
Then I can call BootstrapDialog.Confirm.

If my question is not reasonable, forgive me as I am a beginner.

Kingston
  • 549
  • 1
  • 8
  • 21

2 Answers2

52

You can do it in Javascript:

var jQueryScript = document.createElement('script');  
jQueryScript.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js');
document.head.appendChild(jQueryScript);
Nick Weseman
  • 1,502
  • 3
  • 16
  • 22
3

Using document.write you can include the cdn

 document.write(
      unescape("%3Cscript src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E")
    );
Naga Sai A
  • 10,771
  • 1
  • 21
  • 40