dipesh
04-24-2010, 08:28 AM
Here's my index.htm :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test.</title>
<script language="JavaScript" type="text/javascript">
function funk(){
var head = document.getElementsByTagName("head")[0];
var tnode= document.createElement('script');
tnode.type = 'text/javascript';
tnode.src= '1.js'
head.appendChild(tnode);
doAlert('hello');
}
</script>
</head>
<body>
<A HREF="javascript:funk()">Click!</A>
<div id='pane' class='frame'></div>
</body>
</html>
And 1.js:
function doAlert(str){
alert("I said:"+str);
}
When Click! is clicked in index.htm, funk() is called which dynamically loads the javascript file 1.js. 1.js has the function doAlert() which is called from the last line of funk(). So when doAlert() is called from funk() for the first time, 1.js might not have been retrieved and the error "doAlert is not defined" is thrown.
So, how do I call doAlert() only after 1.js has been completely retrieved?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test.</title>
<script language="JavaScript" type="text/javascript">
function funk(){
var head = document.getElementsByTagName("head")[0];
var tnode= document.createElement('script');
tnode.type = 'text/javascript';
tnode.src= '1.js'
head.appendChild(tnode);
doAlert('hello');
}
</script>
</head>
<body>
<A HREF="javascript:funk()">Click!</A>
<div id='pane' class='frame'></div>
</body>
</html>
And 1.js:
function doAlert(str){
alert("I said:"+str);
}
When Click! is clicked in index.htm, funk() is called which dynamically loads the javascript file 1.js. 1.js has the function doAlert() which is called from the last line of funk(). So when doAlert() is called from funk() for the first time, 1.js might not have been retrieved and the error "doAlert is not defined" is thrown.
So, how do I call doAlert() only after 1.js has been completely retrieved?