Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Source | Q63 [ previous next ]

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?'

©2018 Martin Webb