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
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

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]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

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

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