JavaScript Editor Free JavaScript Editor     JavaScript Debugger 

Main Page

Previous Page
Next Page

1.4. A Brief Introduction to Cross-Browser Development

Knowledge of different browsers, their capabilities, or merely their existence is often an aid in a discipline called cross-browser development. Cross-browser development can be one of the most exciting programming disciplines; unfortunately, in programming, "exciting" isn't usually a good thing. The problem is that, in most instances, cross-browser development is essentially writing the same routines two or more times, slightly different each time. Personally, I get a feeling of satisfaction whenever I get a routine to work, but when coding a cross-browser, getting it to work in one browser is only half the job.

The issue with cross-browser development is that some "features" that are available on one browser either aren't available on another or have slightly different syntax. Imagine the feeling of satisfaction of solving a particularly thorny problem in Firefox only to have the same page crash and burn in Internet Explorer. Take, for example, the serialization of XML in Firefox; it works great, but try the same code in Internet Explorer, and here be monsters!

To avoid the monsters, it is necessary to understand where they usually hang around waiting for the unsuspecting developer. But first let's establish where the monsters don't reside; for example, the standard data types such as Boolean, numeric, and string are pretty safe. The same can be said for the statements, such as flow-control statements and assignment statements.

It is just too bad the same cannot be said for objects and event handlers. At least for me, this is where most of the problems arise. Everything will be going along fine, with the page working perfectly right up to point that either there is a spectacular failure, or worse, the page just simply stops working. Fortunately, with a little knowledge and a little planning, it is possible to avoid these web development monsters that live where the standards don't quite mesh with reality.

1.4.1. Casualties of the Browser Wars

Cross-browser compatibility was probably the first casualty of the Browser Wars that began about 20 minutes after the second web browser was developed. In those days, browser developers had a tendency to play fast and loose with things in an effort to pack features into their browser before the competition. In the rush to be the first with a new feature, or to play catch-up, no thought was given to the web developers who would actually have to program for these browsers.

Because of this, it wasn't unusual to see two browsers with essentially the same functionality, but having entirely different approaches. Look at how the XMLHttpRequest object is implemented in Microsoft Internet Explorer and in Gecko-based browsers such as Firefox. Internet Explorer, which was the first to implement this object, made it part of ActiveX. This means that to create an instance of this object in Internet Explorer, the following syntax is used:

var objXMLHTTP = new ActiveXObject('Microsoft.XMLHTTP');

With Firefox and any other browser that implements the XMLHttpRequest object, the syntax is as follows:

var objXMLHTTP = new XMLHttpRequest();

The reason for this is that ActiveX is a Microsoft-only technology, which means that short of trying to license it from Microsoft, which I can't imagine would come cheap, it was necessary to find another way. And, when found, this other way became the standard for all non-Microsoft web browsers.

1.4.2. Market Share Does Not Equal Right

While I'm on the subject of proprietary technologies, I'd like to point out that market share does not equate to being right. History is full of cases in which the leader, the one with the largest market share, was blindsided by something that he or she didn't realize was a threat until too late. Does anybody remember Digital Research's CP/M? If you haven't, CP/M was the premier operating systems in the days when 64K was considered a lot of memory. In a fractured landscape of operating systems, it had more than half of the operating system market.

Then there was the release of the IBM PC, which offered a choice of three operating systems: CP/M-86, PC DOS, and UCSD D-PASCAL. At the time, everybody thought that Digital Research had the new landscape of the Intel 8086 as theirs for the foreseeable future. Unfortunately, because Microsoft's DOS was $50 less, market share yielded to economic pressure. Microsoft went on to become the leader in computer operating systems, while Digital Research faded into history.

1.4.3. The World Wide Web Consortium, Peacekeepers

During the height of the Browser Wars, there was the definite feeling that web browser technology was advancing at a breakneck pace, so much so that the World Wide Web Consortium seemed to be playing catch-up. It was a case of putting the cart before the horse, with the web browsers getting features and then the recommendations being published, which explains the weirdness with the XMLHttpRequest object.

Now the war is, if not over, at least at intermission, giving us time to get some popcorn and a soda. In addition, whether by accident or by design, this break has given the World Wide Web Consortium time to move once more into the lead. Unfortunately, the damage is done and we're all forced to code around the little differences in the various browsers.

Previous Page
Next Page

JavaScript Editor Free JavaScript Editor     JavaScript Debugger