AJAX Made Easy - Learn AJAX
Home AJAX-Tips

Ensure Ajax’s Browser Compatibility

 Category: AJAX Tips | Add Comment




Sponsored Links


A constant challenge for Ajax developers is to create a website that’s compatible for two major types of web browsers. Netscape based browsers such as Mozilla and Safari has used XMLHttpRequest to access the server and do its business. On the other hand, IE has opted to use Microsoft.XMLHTTP which uses ActiveXObject to render the webpage in IE. At first glance, developers will have a very hard time rendering the object since it virtually uses two separate lines so that it could access the server. However, there is a trick that should be able to easily render the webpage whether if it’s on Mozilla or IE. From the mere fact that even though they pass through different formats on request, they still access the same information and the same coding format could be used in two different browsers. The best thing you could do so that you won’t have to dedicate your webpage in one type of browser is to create a program inside the JavaScript. Developers have created a way of asking the client first on what browser it came from. It’s a little bit tricky but it’s actually very simple when you have used the code more often which should be the case. You don’t just render the webpage in Mozilla as more than half of the world’s net users use only IE. But that doesn’t mean you will leave out other competitive browsers as well. The trick is to determine the browsers first and separate them there. For Netscape based browsers: if (window.XMLHttpRequest) { request = new XMLHttpRequest () { That’s just plain and simple just like what we know about Ajax. On the other hand for IE browsers, the code changes: if (window.ActiveXObject) { request = new ActiveXObject (“Msxml2.XMLHTTP”) That looks very simple. But wait, you have to remember that IE has a lot of versions. Unfortunately, IE is a quiet notorious in changing their program every time a new version is released. Developers have to think about changing their coding again so that it will be optimized for the new version of IE. Although the changes are both for security and efficiency, it could complicate things especially when people use different versions of the browser. If you’re not sure of the IE browser that will be used (most still use IE6 but IE7 is becoming popular) you can use “Microsoft.XMLHTTP” and then branch out to the specific type of browser. There are developers who have even used Msxml2.XMLHTTP.4.0 just to be sure that it’s going to be compatible with IE 4.0. Although there is a talk that the latest edition of IE could actually acknowledge XMLHttpRequest instead of the tedious ActiveXObject, it’s always safe to buffer your site for any browser. Personally, I still use IE6 because of its simplicity compared to IE7. Hopefully IE should make some changes and IE7 could totally be rendered just like its Netscape counterpart. From there developers could concentrate more on security rather than focusing their time more on compatibility and availability to the general users.


Sponsored Links




Next: Returns From the Server



Post Comment


You need to Login to post your comment...

Click here to login

Title:
 
Comment:



Daily Email Updates

AJAX Updates delivered directly to your Inbox...

Enter your email address:

Latest AJAXwith Updates
Sponsored Links
Sponsored Links

Related AJAX Articles

Popular AJAX Articles