Forever Zero
06-18-2008, 04:39 PM
Hi again :)
I'm having a new problem this time...
Basically, I found a way to load an external JavaScript hosted on my server into a webpage. The problem is, when I try and call testFunction() in the test web page, it gives me an error that states:
testFunction is not defined
The code I use for this is:
<html>
<head>
<title> Test Page </title>
</head>
<body>
<script language="javascript">
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://foreverzero.org/test.js';
head.appendChild(script);
script.onreadystatechange = function () {
if (this.readyState == 'complete') testFunction();
}
script.onload = testFunction();
</script>
<p> Woooooooooo </p>
</body>
</html>
Here is test.js (the external script that I am trying to load):
addEventListener(
"load",
function(event) {
alert("load event listener");
},
false
);
function testFunction() {
alert("It worked!");
}
testFunction();
I know it is loading the script for two reasons. The first is that when I load the test page above, the status bar says "transfering data from foreverzero.org" (the test page is not located on that domain name). The second is that the load event listener goes off, and so does the "it works!" alert when I call testFunction() on the very last line.
I cannot figure out why calling testFunction() from the test HTML page will not work. Any advice or ideas is greatly appreciated, I have been struggling with this nearly all week now :(
I'm having a new problem this time...
Basically, I found a way to load an external JavaScript hosted on my server into a webpage. The problem is, when I try and call testFunction() in the test web page, it gives me an error that states:
testFunction is not defined
The code I use for this is:
<html>
<head>
<title> Test Page </title>
</head>
<body>
<script language="javascript">
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://foreverzero.org/test.js';
head.appendChild(script);
script.onreadystatechange = function () {
if (this.readyState == 'complete') testFunction();
}
script.onload = testFunction();
</script>
<p> Woooooooooo </p>
</body>
</html>
Here is test.js (the external script that I am trying to load):
addEventListener(
"load",
function(event) {
alert("load event listener");
},
false
);
function testFunction() {
alert("It worked!");
}
testFunction();
I know it is loading the script for two reasons. The first is that when I load the test page above, the status bar says "transfering data from foreverzero.org" (the test page is not located on that domain name). The second is that the load event listener goes off, and so does the "it works!" alert when I call testFunction() on the very last line.
I cannot figure out why calling testFunction() from the test HTML page will not work. Any advice or ideas is greatly appreciated, I have been struggling with this nearly all week now :(