Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I include a JavaScript file inside another one at runtime?

Tags:

javascript

I need to include a JavaScript file inside another one and use its functions at runtime. The file may exist in my server or in another one.

How can I do this?

like image 754
Eslam Soliman Avatar asked Mar 11 '26 11:03

Eslam Soliman


2 Answers

var sc=document.createElement('script');
sc.src="script.js";
document.getElementsByTagName('head')[0].appendChild(sc);

Use something like this

like image 146
Ruslan Polutsygan Avatar answered Mar 14 '26 00:03

Ruslan Polutsygan


the answer of this question you can find it in the following :Here

something like that visit the article to know more :

<script type="text/javascript">
// Function to allow one JavaScript file to be included by another.
// Copyright (C) 2006-08 www.cryer.co.uk
function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}
</script>

and here are some links on stack overflow :

One Two

like image 21
Eslam Soliman Avatar answered Mar 14 '26 00:03

Eslam Soliman



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!