AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Resources - FAQ - Javascript Q2

FAQ - Javascript Q2



Q2:Opera thinks it is MSIE - what is that all about?

A:It's called spoofing. The default install of Opera identifies itself as MSIE and Opera. Spoofing just gives a browser access to sites that it might not otherwise have been allowed (for whatever reason). While it's not a big deal for surfers it can create problems for scripters.

Take this simple example - take a look at this Question - as you can see Opera and MSIE both use different syntax for width and height which is why the answer suggests object detect.

If you use something like if document.all then its MSIE - if document.getElementById then DOM(opera NS6+ Mozilla MSIE) - if document.layers then do NS4x you can run into problems - You see Opera declares as MSIE and OPERA so you have to apply some logic - best explained by the sniffer I use

var opera = (navigator.userAgent.indexOf('Opera')!=-1); 
var msie = (navigator.userAgent.indexOf('MSIE')!=-1); 
var moz = (navigator.userAgent.indexOf('Gecko')!=-1); 
var Nav4 = (document.layers);  
if (opera && msie || opera){var opera=1; msie=0;} 
if (msie && !opera){msie=1;} 
if(msie || moz){var dom =1;}

This uses the information sent by the browser - it's not the most loved solution but it works well enough.
So what we now have is the ability to easily decide what function for what browser. When you couple this with object detection you have quite a safe method of getting it right.



back to faq




Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]