AJAXAFY-PAGE-START

Tuesday, May 08, 2007

Is Javascript js File Loaded?

I learned a little coding tip over the weekend. I was monkeying around with Microsoft's mapping mashup, and I found that every now and then I'd get an Javascript error. Basically saying that the function I was calling did not exist. I came up with the following idea to deal with the problem:

<html>
<head>
<title>Sample Page</title>
<script src="Includes/sample.js"
language="Javascript"></script>
<script language="Javascript">
function initPage() {
   if (sampleFunc == null) {
      setTimeout("initPage()",100);
      return false;
   } // end if

   // now that it exists, call it!
   sampleFunc();
} // end of function initPage()
</script>
</head>
<body onload="initPage()">

</body>
</html>


This little sample will give the web browser more time to download the sample.js file. But it will do it in such a way as to not lock up the entire browser whilst it's waiting!

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

AJAXAFY-PAGE-END