开发者

Same piece of browser detection code gives diff results for the same browser

I've a simple script to test the browser version. I wrote a simple standalone testing page to test it. When tested on IE 9 it alerted the rigth version 9. The same script whent used in my actual page gives me a different result when tested on the same IE9 browser. (It alerts me with the value 7. I'm confused. Does anyone have any insight?

<script>
if ( $.browser.msie ) {  
     alert( parseInt($.browser.开发者_开发技巧version, 10) );
}
</script>

I've a modal issue for ie 7 and below. I need to check the version and do accordingly


Why are you detecting the browser? That is very strongly discouraged most of the time.

It's better is to use jQuery.support().

To answer your question it could be that IE9 is working in compatibility mode, where it pretends to be an older browser.

Did you include a DOCTYPE in your page?


Check to see if your copy of IE is set to standards mode and whether it's set to mimic one of the older versions for your web page. If you have the IE web tools installed, you can typically see that by hitting F12 and then looking at the browser mode and document mode at the right end of the menu bar. It is possible set to IE to mimic an older version.

Also, you should make sure you have the same DOCTYPE in both pages.

In general checking for a specific browser is not as reliable a technique as doing specific feature detection.


What are you trying to achieve? It's far better to detect the feature(s) you're after instead of a) trying to detect the browser, b) assuming it'd do what it claims to do. Check out http://www.modernizr.com/ if you're after a particular feature.

On the other hand you could just use conditional comments.

<!--[if IE 9]>

<script...


<![endif]-->
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜