`
yangyou230
  • 浏览: 1647960 次
文章分类
社区版块
存档分类

给HTML tag 加浏览器属性到classname

 
阅读更多

有些时候我们需要给html加上一些浏览器属性到classname上,比如os种类,浏览器种类,css是否开启,javascript是否开启。

这样我们可以避免使用css hack,更准确的定位渲染网页的环境。

somethings it is good to setup enviornment class names for a browser.

you can use thes class names later in the css to write specific code for
this is what backbase added to <html> after boot

js gecko gecko6 CSS1Compat Win32


I can create a jquery plugin to do this.
====
var root = $('html');

//detect if javascript is enabled
root.addClass('js');

//detect if cookie is enabled
set a cookie as current time and get it, set to expired afterwards

//this need cookie plugin
$.cookie('the_cookie', 'the_value');
if(!$.cookie('the_cookie')){
root.addClass('noCookie');
}
$.cookie('the_cookie', null);



//detect browser

for(var item in $.browser){
root.addClass(item);
break;
}

root.addClass(item+$.browser.version);



//check quirksmode from bb
Core_Device_Browser_Quirks: document.compatMode ? document.compatMode.indexOf('CSS1Compat') < 0 : true, //Check for quirksmode

//check documentmode in IE
if(document.documentMode && (bb.browser.version != document.documentMode)){
bb.html.removeClass(document.documentElement,'ie'+bb.browser.version );
bb.html.addClass(document.documentElement,'ie'+document.documentMode);
}


var browser_Quirks: document.compatMode ? document.compatMode.indexOf('CSS1Compat') < 0 : true, //Check for quirksmode


if(browser_Quirks){
root.addClass('CSS1Compat');
}else{
root.addClass('QuirksMode');
}


//check os

root.addClass(navigator.platform);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics