Hi All,
I have a page that does the following:
The browser loads a very simple page with a valid head and body, with only a script/noscript pair as content.
In the body, it has a script (script a) that runs a function onLoad. This function dynamically includes a second script (script b), and runs a function in it when it becomes available.
The second script is a .js file that does various work.
Both scripts are parsed by PHP and use the application/x-javascript content type.
Now, I have this all working just fine, except a couple of JS hiccups. JavaScript isn't one of my strong languages, so I'm hoping these are simple issues and somebody can point me in the right direction.
Problem 1: If I do a simple alert('you are in script b'); in the second script, it works as expected. However, if I do anything else, it works fine, and then the browser keeps indicating that it is loading forever. This is the color tween in firefox, or the spinning thing in IE.
I've tried ending the script in different ways, and nothing seems to help. Any idea how to indicate to the browser that the script is all the way loaded? It's a .js file that is forced to parse through PHP.
Problem 2: The second script doesn't seem to be included at all in either Opera or Google Chrome. Works fine in FF/IE, other than the loading issue. Can anyone see if Im using something that isn't compatible in the loading of the second script?
Thanks!
Update:
Thanks for the answers. I actually have firebug, which is why I know everything is working properly (in FF, at least). I don't actually know that the script isn't working in Opera/Chrome, but nothing happens.
It is quite a bit of code =o) I will copy the actual responses out of firebug and post those, so you can see exactly what the code is. As far as the webserver closing the connection, I was thinking that too, but it seems odd that if I make script b into alert('whatever'); it will alert and then stop loading, but it I do everything exactly identical, but make the script document.write('whatever); it will load forever.
Here are the scripts, updated, copied directly from the net tab of firebug:
Note that discoverfire.net is an internal domain, so you won't be able to load anything from there...
Initial HTML page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Welcome!</title>
<style>body { font-family:arial; }</style>
<script language="JavaScript" type="text/javascript" src="http://www.discoverfire.net/analytics/l/a.js">
</script>
<script language="JavaScript" type="text/javascript">
document.onload = Start();
function Start(){
TAFKing_version = '1.0';
TAFKing_lkey = '19-8O-KKA8HV';
TAFKing_Lander();
}
</script>
</head>
<body>
<noscript>
Oops! We can't forward you properly because your JavaScript is turned off.<br /><br />
<a href='http://www.discoverfire.net/analytics/l/noscript/19-8O-KKA8HV.html'>Please click here to continue.</a>
<img src='http://www.discoverfire.net/analytics/l/imp/19-8O-KKA8HV.png' border='0' alt='tell a friend' />
</noscript>
</body>
</html>
** Script A (...a.js): http://www.discoverfire.net/analytics/l/a.js **
function TAFKing_Lander(){
version = TAFKing_version;
lkey = TAFKing_lkey;
var scrb = document.createElement('script');
scrb.type = 'text/javascript';
scrb.src = 'http://www.discoverfire.net/analytics/l/b.js?lkey='+lkey+'&version='+version+'&cb=4eohe8e65'
;
document.getElementsByTagName('head')[0].appendChild(scrb);
Interval = setInterval("Waiter()", 10);
return;
}
function Waiter(){
if(window.TAFKing_LanderB) {
clearInterval(Interval);
TAFKing_LanderB();
}
}
Script B (...b.js): http://www.discoverfire.net/analytics/l/b.js?lkey=19-8O-KKA8HV&version=1.0&cb=4eohe8e65
function TAFKing_LanderB(){
document.write("there are just a whole bunch of doc.writes here that build a simple table");
}