JavaScript
  Home arrow JavaScript arrow Page 3 - Detect Browser Compatibility with the Requ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Detect Browser Compatibility with the Request Object
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-07-17

    Table of Contents:
  • Detect Browser Compatibility with the Request Object
  • Using a Function for Checking Compatibility
  • Ajax Basics
  • Ajax Basics continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Detect Browser Compatibility with the Request Object - Ajax Basics


    (Page 3 of 4 )

    In this case, thewindow.XMLHttpRequestobject will not exist in the browser object model. Therefore, another branch of theiftest is necessary in your code:

      else if (window.ActiveXObject){
         
    request=new ActiveXObject("Microsoft.XMLHTTP");
          if (! request){
             
    request=new ActiveXObject("Msxml2.XMLHTTP");
          }
         
    if(request){
      request.onreadystatechange=handleResponse;
                request.open(reqType,url,true);
                request.send(null);
          }
      }

    This code fragment tests for the existence of the top-levelwindow objectActiveXObject, thus signaling the use of Internet Explorer. The code then initializes the request using two of a number of possibleActiveXprogram IDs (here,Microsoft.XMLHTTPandMsxml2.XMLHTTP).

    You can get even more fine-grained when testing for different versions of the IE request object, such asMsxml2.XMLHTTP.4.0. In the vast majority of cases, however, you will not be designing your application based on various versions of the MSXML libraries, so the prior code will suffice.

    The code then makes one final check for whether the request object has been properly constructed (if(request){...}).

    Given three chances, if therequestvariable is stillnullorundefined, your browser is really out of luck when it comes to using the request object for Ajax!

    More JavaScript Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Ajax Hacks," published by O'Reilly. We...
       · Why go through all the work.. I think the approach that JAK uses to discover...
     

    Buy this book now. This article is excerpted from the book Ajax Hacks, written by Bruce W. Perry (O'Reilly; ISBN: 0596101694). Check it out today at your favorite bookstore. Buy this book now.

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT