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:

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

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


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!



Post a Comment

Subscribe to Post Comments [Atom]

<< Home