Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Internet Explorer
Expertise: Beginner
Jul 26, 1999

DHTML Loads Faster Than Accompanying HTML

Question:
I often have the problem in which the DHTML on my page loads faster than the accompanying HTML. Therefore, users are enticed to click away at elements, which trigger events that act on HTML that have not yet loaded. The result is a script error. I know I can trigger a function onload that continuously polls the readystate of the document. While it polls, 'document.onmousedown = null' works in nullifying mouse clicks. But how do I reset document.onmousedown to resume normal operation after the document's readystate is true?

Answer:

You're on the right path here, but rather than polling, you may want to just wrap your function bodies:

function mouseclickevent(){
   if (document.readyState=="complete"){
      // perform your processing.
      }
   }

You could also hold off adding the events to the objects until after the readystate is "complete":

function document_onreadystatechange(){
   if (document.readyState=="complete"){
       // handle any final initializations
       myImage.onmousedown=mouseclickevent;
       }
   }
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap