How do I link to a javascript file within a javascript file?

Possible Duplicate:
How do you dynamically load a javascript file? (Think C's #include)
Include JavaScript file inside JavaScript file?

I know that one can link to external javascript files with html code akin to:

<script type="text/javascript" src="http://external.com/code.js"></script>

Is there a way to do this within a javascript (.js) file?


Create a script element and append it to the DOM. That should load your other script.

var newScript = document.createElement("script");
newScript.setAttribute("type","text/javascript");
newScript.setAttribute("src","http://external.com/code.js");
body.appendChild(newScript);

你可以尝试在这个问题中给出的答案。

链接地址: http://www.djcxy.com/p/42462.html

上一篇: 用Javascript加载jQuery并使用jQuery

下一篇: 如何链接到JavaScript文件中的JavaScript文件?