Author Topic: Internet Explorer DOM readiness problem and solution explained  (Read 19256 times)

0 Members and 1 Guest are viewing this topic.

Offline aboututila

I am writing this as a result of helping several users with problems which were eventually diagnosed as being caused by the Microsoft Internet Explorer DOM readiness, domready or Event.domReady bug/problem.

Problem symptoms:
- Problem DOES NOT occur when using Gecko based browsers (Firefox, etc) and Presto based browsers (Opera, etc).
- Problem DOES occur when using Trident (Internet Explorer) and WebKit (Safari, Google Chrome) based browsers AND JavaScript(s).
- Problem is most likely to occur with the standard mootools JavaScript libraries used by Joomla! 1.5.x or other Joomla! Extensions (such as SOBI2), but can occur with any JavaScript that relies on DOM readiness

Depending on;
  Internet Explorer Browser settings for;
     Internet Options->Advanced Settings->Browsing
     - Disable script debugging (Internet Explorer)
     - Disable script debugging (Other)
     - Display a notification about every script error
     - etc, etc
  and which version of Internet Explorer is used (6, 7, 8, 8 in compatibility mode),
  and what other IE Browser options are enabled or disabled,

then,
 Internet Explorer;
  may not (obviously) report any errors,
  may report in bottom left corner of browser window the message "Done, but with errors on page",
  may report "Operation Aborted",
  may report "HTML Parsing Error",
  may display "Internet Explorer cannot display the webpage"
  may report some other error,

and,
   the User browsing the web site may experience the problem as;
   requested page to be displayed is inaccessible - "Operation aborted"
   or
   only part of the expected page/document display can be seen on screen,
   or
   the page/document display is incomplete, (missing elements which should be displayed)
   or
   symptoms may vary on Browser "page refresh"

This is often a difficult problem to diagnose since the symptoms are so varied and users can report the problems in a variety of ways, often not mentioning which Browser (and hence which Layout engine) they are using.
Clearly, the Why do I receive an "Operation aborted" error message when I visit a Web page in Internet Explorer? is an obvious symptom and easier to diagnose and hence resolve.

In the above link reference, Microsoft imply that the problem is resolved with IE8, but in practice it is often just more difficult to diagnose, Refer What Happened to Operation Aborted?

Problem Solution (for mootools):
Replace all 'domready' (or equivalent JavaScript functions) with 'load'
and to save you having to search and modify potentially hundreds of JavaScripts, there is a convenient Joomla! Extension ReReplacer, that can do this for you.
Refer IE Operation Aborted - EASY FIX!

Explanation:
I am no JavaScript expert, or expert at anything, so the following is a layman's (or conceptual) explanation of the problem.

What is 'domready'?
'domready' is a JavaScript event handler built into many JavaScript libraries to delay execution of JavaScripts until the Browser has finished loading the DOM or DOM Tree and is ready to manipulate it. Different JavaScript libraries have defined different names for this event handler. mootools uses the name domready, JQuery uses 'ready' , but essentially they all do the same thing, delay execution of JavaScript code until the Browser has finished loading the DOM and it is ready to be manipulated. Gecko based browsers (Firefox, etc) and Presto based browsers (Opera, etc) support two proprietary Events known as DOMContentLoaded and DOMFrameContentLoaded which occur after the page/document/frame has loaded but before all the slow images, applets, Flash movies, etc, have completed loading. Unfortunately, Trident based browsers (Microsoft Internet Explorer) and WebKit based browsers (Safari, Google Chrome, etc) do not provide such a proprietary event, so it has to be emulated/simulated with JavaScript work-arounds.

What is the DOM?
DOM is an acronym for Document Object Model.
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing 'elements' in documents in constructed in HTML and XML.
The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.
The HTML DOM defines the objects and properties of all HTML elements, and the methods (interface) to access them.
In other words: The HTML DOM is a standard for how to access, change, add, or delete HTML elements in a HTML document.
Refer HTML DOM Introduction
Unfortunately the W3C DOM does not define a 'DOM ready' DOM event in either the W3C Level 1 or Level 2 specification. I believe the W3C draft (DOM) Level 3 Events Specification specifies and event DOMActive which may be an eventual solution to the problem (assuming it is implemented by all Browsers!)

When is the DOM ready?
Almost every Browser has a method or menu option for showing the HTML "Page Source" of the currently viewed Page/Document. The DOM is 'ready' when the Browser has received and parsed the entire source of this HTML Page/Document from either the Server or its own cache, but before the Browser has loaded all HTML Multimedia <img />, <object />, <embed>, etc, files, and CSS background-image files.

Why is DOM ready used?
Before a domready function was developed, JavaScript programmers used the 'window.onload' event to trigger the execution of a JavaScript. However using the 'window.onload' has two issues;
(i) the event only occurs after the Browser has loaded ALL Page/Document elements (such as image files, flash files, etc), and as a consequence web pages can appear to be slow to interact with, (especially as many menu systems utilize JavaScript),
(ii) other JavaScripts may overwrite/redefine what should occur on the 'window.onload' event.
'domready' provides a convenient way of solving these two problems.

How is the DOM used?
There are many ways JavaScripts can use the DOM.
Joomla!, SOBI2, and many other Joomla! Extensions use DOM Events and JavaScript to dynamically inject additional HTML into, or manipulate the existing HTML of, the 'standard' HTML output in a document. Other uses are to dynamically change the CSS properties of HTML elements. This is how mootools and other JavaScripts achieve their visual effects. (Refer http://www.mootorial.com/wiki/mootorial/06-fx/03-fx.transitions)

For example,
(i) Joomla! Tooltips are HTML elements that are dynamically displayed when 'mousing' over 'standard' document HTML elements.

(ii) SOBI2 uses JavaScripts to dynamically display 'Category Selection' in the 'Please Select a Category' section of the Add Entry Form

(iii) All Joomla! WYSIWYG Editor plugins (as used by SOBI2) use JavaScript to implement their editing functions.

So what is the problem with Internet Explorer?
Firefox and Opera 9+ (for example) have a check for DOM readiness (DOMContentLoaded and DOMFrameContentLoaded) built into the Browser proprietary Layout engine functionality (Gecko for Firefox and others, Presto for Opera and others), but the Trident Layout engine used by Internet Explorer does not, so JavaScript programmers have to implement a workaround for Browsers using the Trident and other Layout engines to determine when the DOM is ready.
Refer Relying on DOM readiness to invoke a function (instead of window.onload)

Joomla! relies on mootools to check for DOM readiness.
Mootools v1.11 and 1.2.x has a bug/flaw in that it is reporting DOM ready in Internet Explorer before the DOM is ready, and apparently this is not going to be fixed until mootools v2.0. Refer domready is fired after before load in all IE versions

I don't understand, what is the problem with Internet Explorer?
I will try and explain a little further.
When using Internet Explorer with mootools and JavaScripts that rely on mootools, it is possible that those JavaScripts may begin executing before the DOM has completely loaded and accessible to those JavaScripts.
So if, for example, a JavaScript was designed to insert the HTML <span style="color:red;">This is a Test</span> between the tags <div class="test">and </div> that JavaScript would fail if Internet Explorer had not yet loaded and parsed the part of the document that contained the tags <div class="test"> and </div>.
This is also why the problem can be variable, since the time taken to load the DOM HTML varies depending on a number factors.

So this is a SOBI2 problem?
Not that I am aware of.
In every instance where I have encountered a problem, the problem was actually caused by Joomla! and mootools. It just appears to be a SOBI2 problem, because you are looking at/for SOBI2 output, but that output has been aborted by the Browser, usually because of a Joomla! tooltip or some other mootools related event elsewhere in the page/document being output.

So this is a mootools problem?
Well yes and no.
If the Trident Layout engine used by Internet Explorer had the capability to internally determine when the DOM was ready, (like the Gecko Layout engine has), then the problems would be minimized. In the meantime, mootools and other JavaScript libraries have to implement work-arounds for the Trident and other Layout engines.
It is not just a mootools problem, the Yahoo! library has a similar problem. (Refer When IE says DOM is ready but it ain't true)

So this is a Microsoft Internet Explorer problem?
Well yes and no.
IE/Trident does not implement all W3C standard DOM events (Refer Comparison of layout engines (Document Object Model) - Events) as completely as other Browsers do, but what else is new, it's Microsoft right? But to make things even more difficult for software developers, Microsoft IE does not have equivalent events for all W3C standard events, and also implements a different Advanced event registration model.

So there is no easy solution for cross browser support for JavaScripts?
Correct,
at least not if you want to have 'fast' user interaction with a web page rather than waiting for the entire page contents (image files, flash files, etc) to have finished loading before executing JavaScript, and
at least not while Microsoft continues to define and implement it's own proprietary extensions that diverge from the W3C Standards and the proprietary extensions used by the other major web browsers.

Also see
SOBI2 and JavaScript Conflicts
Diagnosing JavaScript problems
What is a layout engine?
List of layout engines
Comparison of layout engines
Comparison of layout engines (HTML)
Comparison of layout engines (XML)
Comparison of layout engines (XHTML)
Comparison of layout engines (graphics)
Comparison of layout engines (CSS)
Comparison of layout engines (DOM)
Comparison of layout engines (HTML 5)
Comparison of layout engines (ECMAScript)  - (particularly JavaScript)
Comparison of layout engines (SVG)

I hope this helps - Mark
« Last Edit: 01. July 2010, 23:42:56 by aboututila »
Country: Honduras Honduras |  OS: Windows XP Windows XP |  Browser: Firefox 3.5.3 Firefox 3.5.3 | View Profile

Offline dsmflash

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #1 on: 15. October 2009, 06:19:35 »
I am using RT Affinity template and the issue seems to be with the template.

i've tried the rereplace method, which does not work, but is all over the net.

how do you find the culprit js file?

thanks. i've tried everything
Country: United States United States |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.5.3 Firefox 3.5.3 | View Profile

Do you want continued ongoing development, new features and active support?
Please write a review or just vote for SOBI on JED.

Offline aboututila

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #2 on: 15. October 2009, 21:23:52 »
dsmflash,

In an attempt to help you and others I have written the following posting;
Diagnosing JavaScript problems.
Perhaps the above topic may give you some clues/ideas about how to determine your problem.

I hope this helps - Mark
Country: Honduras Honduras |  OS: Windows XP Windows XP |  Browser: Firefox 3.5.3 Firefox 3.5.3 | View Profile

Offline dsmflash

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #3 on: 15. October 2009, 22:46:02 »
thanks
Country: United States United States |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.5.3 Firefox 3.5.3 | View Profile

Offline Belaire Technologies

  • Bronze Sponsor
  • Sobi Experte
  • *
  • Posts: 565
  • formerly - yoobuild
  • Reviews:

    What is it?

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #4 on: 28. January 2010, 18:12:13 »
Well explained!  As you probably already have seen my fixes in the forums I disagree with you about one thing.

IE is the problem.   IE does not implement standards.  Never has.

They make a developers job harder.  Their browser is slow and it sucks.  It's full of holes (not that any other browser is not). 

Quite informative and I will add this to thread.
No one answering your sobi2 questions? Try our secondary support @ belairetech.com.  Sign in an open a ticket.  Sorry no large development questions please.  For now the service is free to sobi2 members.
Country: United States United States |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: Firefox 3.6 Firefox 3.6 | View Profile Belaire Technologies

Offline aboututila

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #5 on: 28. January 2010, 20:35:54 »
Yoobuild,

Well explained!

Quite informative ...
Thank you.
I agree with you that IE sucks and is one of the major problems for web developers.
I have seen many of your posts and you are certainly more expert than I.

As you probably already have seen my fixes in the forums I disagree with you about one thing.
IE is the problem.   IE does not implement standards.  Never has.
I agree that IE is a major problem, but I would suggest that IE does implement standards,
refer;
The Web Standards Project - IE8 Has Arrived
Standards Compliance Updates in Internet Explorer 8

I suggest a more correct statement would be that Internet Explorer does implement W3C standards, but compared to other major browsers, does not have the same degree of completeness, is always well 'behind the curve' in implementing draft standards, and has many more proprietary extensions (which Microsoft encourages IE Developers to use through the use of Microsoft Web Development Tools) .
Refer
Acid2 - web standards testing
Comparison of layout engines (Cascading Style Sheets))
Also the Microsoft Developers appear to have a significant 'not invented here' attitude when it comes to W3C standards, or perhaps they have a significant problem maintaining backwards compatibility to the installed base of older (and less standards compliant) IE versions.

I would make the point that with regard to the 'domready problem', arguably the 'root' of the problem is caused because a 'domready' event has not been defined in current W3C standards, (as far as I am aware).
 
And... It is not only the way that IE handles JavaScripts (Refer Diagnosing JavaScript problems - Item (5) JavaScript problems in Internet Explorer) , but CSS implementations and CSS bugs (Refer Explorer Exposed! - The weird and wonderful world of Internet Explorer and those horrible Quirks Mode problems (Refer Quirks mode and strict mode).

Unfortunately, my web site(s) statistics show me that Internet Explorer is still very much the dominant browser used to access those sites. I also guess that IE is also the most prolific Browser used on the Web, so I guess, however painful, web developers have to learn to accommodate it.

Do not get me wrong. I am not trying to defend IE or Microsoft, just point out that, however regrettable, IE is something that web developers have to learn to live with for the foreseeable future.

The following graphic was first published in 2006 and I found it very amusing, but unfortunately accurate. In my opinion, the graphic is still relevant today (if not more so, because of all the different version of Internet Explorer currently in use).
[attachimg=1]
Regards - Mark
« Last Edit: 28. January 2010, 20:42:19 by aboututila »
Country: Honduras Honduras |  OS: Windows XP Windows XP |  Browser: Firefox 3.5.7 Firefox 3.5.7 | View Profile

Offline Belaire Technologies

  • Bronze Sponsor
  • Sobi Experte
  • *
  • Posts: 565
  • formerly - yoobuild
  • Reviews:

    What is it?

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #6 on: 29. January 2010, 00:49:47 »
LOL - hear you.  There is still IE out there.  I really don't even worry about my site to much for IE.  I probably should though but I just don't have the time to keep IE hacks up-to-date.

IE8 is suppose to be more complaint but it's not quite there either.  I think that should take a copy of firefox and add their little e logo and call it internet explorer.  I bet only 5% people would know the difference (no to say IE is used by dummies).  Most people don't even care.

I'm no expert at this but you gave quite a descriptive thread to the issue and you were dead-on.  Unless someone can come up with a explanation better than yourself.  I will stand behind the issue that it is an IE problem.

Cheers
No one answering your sobi2 questions? Try our secondary support @ belairetech.com.  Sign in an open a ticket.  Sorry no large development questions please.  For now the service is free to sobi2 members.
Country: United States United States |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: Firefox 3.6 Firefox 3.6 | View Profile Belaire Technologies

Offline youngboy815

Re: Internet Explorer DOM readiness problem and solution explained
« Reply #7 on: 30. July 2010, 18:51:23 »
They make a developers job harder.  Their browser is slow and it sucks.  It's full of holes (not that any other browser is not). 

Quite informative and I will add this to thread.
Country: China China |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: MS Internet Explorer 7.0 MS Internet Explorer 7.0 | View Profile

Tags: