spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / detection current pageTo page 2To page 3
[next]

Object Detection in the New Browser Age

Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow

By Eddie Traversa (etraversa@dhtmlnirvana.com)

Quite often, developers turn to object detection routines to differentiate between browsers. This practice is quite widespread and at least at a conceptual level the adoption of utilizing object detection routines is justified. However, as we shall soon see, the practice of using object detection routines in Web pages can often be undesirable. All too often, the type of object used by the developer and designer doesn’t make a distinction between certain browsers. Therefore, we need to put a little more thought into object detection routines, so that they can better make that all important distinction between browsers.

Object detection is the practice of finding an object that is supported by a specific browser and then using that object to form the basis of a conditional statement. For example, if we wanted to code only for Internet Explorer we could use the document.all collection to separate Internet Explorer from other browsers.

if (document.all) {
// do something funky here
}

One of the advantages of object detection is that we surpass the hurdle of a browser hiding their identity completely, which can make the detection of user agent strings problematic.

Despite the obvious advantages of object detection, Web developers and designers alike all too frequently make the mistake of not correctly separating browsers through their object detection routines.

For example consider the following simple function:

function whatBrowser() {
 if (document.all) {
	alert('just a test')
    }
}

The alert will trigger correctly in Internet Explorer 4 and above as we would expect. However, the alert will also trigger in Opera based browsers because Opera also supports the document.all collection. Clearly, this is often undesirable as we may be using code specific Internet Explorer features that are not supported in Opera; the consequence of which often results in a badly broken page in Opera.

To complicate matters, the problem isn’t just specific to Opera and Internet Explorer based browsers. For example, consider the following scenarios:

  1. A developer finds a problem on Internet Explorer 5 for Windows, but the problem doesn’t exist on Internet Explorer 5.5+, Internet Explorer 6 and Internet Explorer 5 on Mac. The developer then needs to find an object that is specific to Internet Explorer 5 which doesn’t allow other browsers to use the code in the conditional statement.

  2. A developer decides to use standards based coding, but finds that the appearance of their Web page is dissimilar between Internet Explorer 6 and Netscape 7.

  3. A developer utilizes some Internet Explorer 5.0+ features but notices that Mac IE5 differs considerably from windows IE5.


home / programming / javascript / detection current pageTo page 2To page 3
[next]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark

Created: February 3, 2003
Revised: February 3, 2003

URL: http://webreference.com/programming/javascript/detection/