I keep getting an error of "Invalid Pointer", which could be due to the fact that script somehow ran before all the objects and elements have completely loaded. After a exhausting search, I was able to find the solution in an easy to understand blog by Dean Edwards at his site: http://dean.edwards.name/weblog/2005/09/busted/ and http://dean.edwards.name/weblog/2006/06/again/ .
The solution on my specific problem was to have my external page loaded after all objects and elements are finish on the main page. One of the solution presented was to have defer on the <script> tag. According to him, this only works on external files, which pretty much the solution on my problem. Here is how it would look:
<script defer type="text/javascript" src="external.js"></script>
Ok, so I placed that on my website. Still an error occured, I have no choice, but to just have my functions in an external file, while I do the window.onload on the main page.
After placing the window.onload on the main page, this time the error is on the browser not recognizing the object. So part of the solution is for IE to detect, if everything is ready. Answer is still in Deans blog, but a lot different for my case since, I want to use an external file and detect if all is ready, before I run the function. My own solution is to have the following script, based on his example:
document.onreadystatechange = function() {
if (this.readyState == "complete") {
somefunction();
}};
I just replaced his script object with document object, for me to see that document has all been loaded. This only works on IE according to some websites, but when I placed it to run on other browser was detected, it still performs as it should.
So, the whole solution for me was to detect in PHP, the browser and version to run this work around:
<script defer type="text/javascript" src="external.js"></script>
<?php
if(isset($_SERVER['HTTP_USER_AGENT']) && ((strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') !== false) || (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) || (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false)))
{
?>
document.onreadystatechange = function() { if (this.readyState == "complete") {
somefunction();
}};
<?php
}
else
{
?>
<!-- Other Browsers Script -->
<?php
}
?>
The following is the source for the onreadystatechange: http://help.dottoro.com/ljerfwdm.php