Defer the call of an external .js file

J

Jim Adamson

Hi

I want to defer the call of an external .js file so that when the link
in the page is clicked, the .js file is downloaded and
included in the page. The link would also pass on some arguments to
the function in the page. Once the .js file is successfully
downloaded/included, I would then like to pass on the arguments from
this function to the function
that is within the .js file and call the function that's inside the
..js file from the function in the page. Is this possible ? Here's the
sort of thing that I've tried but I get "Is not defined errors"
presumably because the function in the .js file hasn't been
incorporated into the page after clicking the link.


<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function dload(id,name,street)
document.write('<script src="whatever.js"><\/script>');
jsfunction(id,name,street)
</SCRIPT>
</head>
<body>
<a href="javascript:dload('12345','john','Westwood St');">Link</a>
</body>
</html>

thanks
Jim
 
E

Evertjan.

Jim Adamson wrote on 15 dec 2004 in comp.lang.javascript:
I want to defer the call of an external .js file so that when the link
in the page is clicked, the .js file is downloaded and
included in the page.

Make two similar pages, one with, one without the .js

However such belated loading is never necessary,
as immediate loading and clever programming suffice.

I suppose you are ready for some serverside programming.

;-}
 
R

RobB

Jim said:
I want to defer the call of an external .js file so that when the link
in the page is clicked, the .js file is downloaded and
included in the page.

The appropriate word here is 'load' - you don't call files.

Just use an ordinary link. All browsers afaik will dump imported files
with mimetype 'application/x-javascript' right into the JavaScript
execution environment without disturbing the loaded page, regardless of
file extension, allowing dynamically assembled files - '.php', '.asp',
'.jsp' e.g. - to be accessed as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top