JS 根据屏幕大小以及浏览器加载不同 CSS 样式

2012-11-15未知95571Javascript & jQuery

闲来没事写个 CSS hack。    


window.onload = loadStyleFun();

function loadStyleFun(){
	var _lQ = window.navigator.userAgent;

	if ( _lQ.indexOf("MSIE") >= 0 ){
		var _IE_1024 = "IE_1024.css";
		var _IE_1280 = "IE_1280.css";
		checkScreenSize( _IE_1024, _IE_1280 );
	}else if( ( _lQ.indexOf("Chrome") >= 0 ) || ( _lQ.indexOf("Firefox") >= 0 ) ){
		var _Other_1024 = "FF_GG_1024.css";
		var _Other_1280 = "FF_GG_1280.css";
		checkScreenSize( _Other_1024, _Other_1280 );
	}else{
		var _Other_1024 = "other_1024.css";
		var _Other_1280 = "other_1280.css";
		checkScreenSize( _Other_1024, _Other_1280 );
	}
}

function checkScreenSize( CSS_1024, CSS_1280 ){
	var _width = document.documentElement.clientWidth;
	if ( _width < 1280 ){
		setActiveStyleSheet( CSS_1024 );
	}else{
		setActiveStyleSheet( CSS_1280 );
	}
}

function setActiveStyleSheet( css ){
	document.getElementsByTagName("link")[0].href = "./style/" + css;
}


兼容 屏幕大小 浏览器  

9557

1

写评论

  昵称
  验证码