Skip to content

Browser Feature Detection

Often when dealing with different browsers, this is something I encounter recently (with jQuery):

var ie6 = $.browser.msie && $.browser.version == '6.0';
	target.css('position','absolute'); //IE6 has no 'fixed' position

This code is copied from a library which aims at create an overlay for modal box. From IE7 onwards, CSS style position ‘fixed’ is supported, but not in IE7’s quirks mode. So the above code would fail. The solution is let IE7 run at correct doctype. e.g.:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">

But the code is still fragile to the environment. In jQuery, you can use $.support to get a set of feature detect properties. So, the code can become:


But it is still based on the assumption that “no support on boxModel = no support on fixed position”, which is “politically incorrect”.

Jacky13 Jan 10 11:03 am 寫關於科技

Tags: , , , [ 永久連結 | 引用 | 回應 RSS ]