Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q63 Is it possible to import a .js file from another .js file?

irt.org | Knowledge Base | JavaScript | Source | Q63 [ previous next ]

Q63 Is it possible to import a .js file from another .js file?

Within the import.html file:

<body>
<script src="import1.js">
</script>

<script language="JavaScript"><!--
document.write(test1());
document.write(test2());
//--></script>
</body>

Within the import1.js file:

function test1() {
    return '<scr' + 'ipt src="import2.js">' + '<\/script>';
}

Within the import2.js file:

function test2() {
    return 'Hello World';
}

Note for it to work test1() must be called whilst rendering the page. If you call it after the page has rendered then it might overwrite the current document.

Feedback on 'Q63 Is it possible to import a .js file from another .js file?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.