views:

22

answers:

3

Hi,

I'm getting javascript errors for all my links that contain javascript events. This is caused by the user trying to click on a link, and yet the javascript files have not been loaded yet.

How can I resolve this issue? Is there any way of blocking the javascript events until all the javascript files are loaded?

Thanks.

+1  A: 

If the code for whatever you're doing is declared above the link (i.e. the place where the code is used) you should not have this problem.

I'm unsure how different browses will handle the order of loading if the JavaScript is in an external file.

Noon Silk
+1  A: 

The conventional way of handling this is to hide the page content behind a DIV until the onLoad() event fires, then reveal it by hiding the DIV.

Edited to add

I see his problem as not being specifically about javascript, but the general problem of keeping the user from interacting with the page before it's loaded.

egrunin
No offense here, but I've *never* heard of this being a "conventional" way of doing things. This is a very bad solution to the problem IMO.
Nick Craver
+1  A: 

JavaScript blocks natively. Just ensure that your scripts are loaded before your links, i.e. within the head tag.

The above should fix it, but you should look into Progressive Enhancement

Jason McCreary

related questions