[thelist] Loading JavsScript file (*.js)

Fernando Gómez fgomez at criba.edu.ar
Thu Sep 19 15:30:00 CDT 2002

From: "Syed Zeeshan Haider" <szh at softhome.net>
Sent: Thursday, September 19, 2002 5:20 PM

> I have a very large JavaScript file (size is about 40 KB). I have inserted
it in
> HTML document with following line:
> <script language="JavaScript" src="myscript.js"></script>
> This file definitely increases the loading time of the HTML document as it
> along with HTML.
> Is it possible to load this file only when a user clicks on a certain
button? I
> mean can I control its loading?

If you use an ID attribute for the <script> element, then (I'm not sure) you
could set its SRC attribute using an event handler:

<script id="myScript" language="JavaScript" src="myscript.js"></script>

<button onclick="document.getElementById('myScript').src='myscript.js'">
Load script

Fernando Gómez

More information about the thelist mailing list