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

Q1671 How can I prevent an external JavaScript file from loading until called for by the click of a button?

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

You can load the JavaScript source file into an inline frame (Internet Explorer all versions and Netscape Navigator 6+), or you could load it into a layer (Netscape Navigator 4):

<html>

<head>

<script language="JavaScript"><!--
function loadCode(src) {
  if (document.getElementById) {
    document.getElementById('myFrame').src = src;
  }
  else if (document.all) {
    document.frames['myFrame'].src = src;
  }
  else if (document.layers) {
    document.myLayer.load(src,0);
  }
}
//--></script>

</head>

<body>

<iframe id="myFrame" src="about:blank" width="100" height="100"></iframe>
<ilayer id="myLayer"><ilayer>

<form>
<input type="button" value="Load code" onClick="loadCode('test.htm')">

</form>

</body>

</html>

And in test.htm:

<script language="JavaScript" src="test.js"></script<

And in test.js:

alert('Hello world');

Feedback on 'Q1671 How can I prevent an external JavaScript file from loading until called for by the click of a button?'

©2018 Martin Webb