JavaScript
  Home arrow JavaScript arrow Page 2 - 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 
Sun Developer Network 
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 - Using a Function for Checking Compatibility


    (Page 2 of 4 )

    Wrap the compatibility check inside a JavaScript function, then call this function before you make any HTTP requests using the object. For example, in Mozilla-based browsers such as Netscape 7.1 and Firefox 1.5 (as well as in Safari 2.0 and Opera 8.5), the request object is available as a property of the top-levelwindowobject. The reference to this object in JavaScript code iswindow.XMLHttpRequest. The compatibility check for these browser types looks like this:

      if(window.XMLHttpRequest){
         
    request = new XMLHttpRequest();
      
    request.onreadystatechange=handleResponse;
         
    request.open("GET",theURL,true);
         
    request.send(null);
     
    }

    The JavaScript variablerequest is to a top-level variable that will refer to the request object.

    As an alternative model, the open-source library Prototype uses object-oriented JavaScript to wrap the request object into its own object, as in the object Ajax.Request (see Chapter 6).

    If the browser supportsXMLHttpRequest, then:

    1. if(window.XMLHttpRequest)returnstruebecause theXMLHttpRequestis notnullorundefined.
    2. The object will be instantiated with thenew keyword.
    3. Itsonreadystatechangeevent listener (see the section “XMLHttpRequest” earlier in this chapter) will be defined as a function namedhandleResponse()
    4. The code calls the request object’sopen()andsend()methods.

    What about Internet Explorer users?

    Microsoft Internet Explorer–related blogs mentioned, at the time this book went to publication, that IE 7 would support a native XMLHttpRequest object.

    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

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






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