Take the 2-minute tour ×

I have 8 javascript file in html,how can i check if js file is loaded or not and also handle error if any one of the file is not loaded in cross browser

Thanks in advance!

share|improve this question
You can also use firebug to analyse which files gets loaded and which doesn't and the reasons for the files as to why aren't they getting loaded... –  Mahendra Apr 19 '11 at 6:54
i must check whether the js is loading in all broswer also.so i need to display success msg,once the js is loaded –  Tarun Apr 19 '11 at 7:08

5 Answers 5

You could use "try catch" to avoid the errors when accessing non-existing function or data, and react as you want

share|improve this answer

You can try using the "try-catch" block in javascript.

To use it you can call any one function / refer a variable of the file you want to check inside the try block. If it does not enter the 'catch' block then it means that the file is loaded.

You can also use Firebug to check which files gets loaded and which aren't and the errors as to why aren't they getting loaded.

Hope this helps. And don't forget to mark it as an anwser if you find it helpful.

share|improve this answer

Use firebug or equivalent to spot 404's.

If a script loads in one browser, it will load in another browser, no crossbrowser issues here.

To handle load errors, use a script loading framework like RequireJS and dynamically load scripts.

Sidenote: Accept good awnsers to boost your own reputation, people will awnser questions faster/more often when you have a good rep.

share|improve this answer

When adding a js file dynamically, have a line of script that adds an element to the DOM, with a certain unique ID... Then cHeck for existence of that element in the DOM. If that element exists, it means that the js file was loaded.

share|improve this answer

you could add namespaces/global variables to every file and check as follows:

in fileName.js:
 window.fileName = true;

then, to check:

<script> if (!window.fileName) {...} </script>
share|improve this answer

Your Answer


