首页  >  文章  >  web前端  >  用js自动判断浏览器分辨率的代码_基础知识

用js自动判断浏览器分辨率的代码_基础知识

WBOY
WBOY原创
2016-05-16 19:20:031003浏览
复制代码 代码如下:

<script> <BR><!-- <BR>if (window.navigator.userAgent.indexOf("MSIE")>=1) <BR>{ <BR>var IE1024=""; <BR>var IE800=""; <BR>var IE1152=""; <BR>var IEother=""; <BR>ScreenWidth(IE1024,IE800,IE1152,IEother) <BR>} <BR>else{ <BR>if (window.navigator.userAgent.indexOf("Firefox")>=1) <BR>{ <BR>var Firefox1024=""; <BR>var Firefox800=""; <BR>var Firefox1152=""; <BR>var Firefoxother=""; <BR>ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother) <BR>} <BR>else{ <BR>var Other1024=""; <BR>var Other800=""; <BR>var Other1152=""; <BR>var Otherother=""; <BR>ScreenWidth(Other1024,Other800,Other1152,Otherother) <BR>} <BR>} <BR>function ScreenWidth(CSS1,CSS2,CSS3,CSS4){ <BR>if ((screen.width == 1024) && (screen.height == 768)){ <BR>setActiveStyleSheet(CSS1); <BR>}else{ <BR>if ((screen.width == 800) && (screen.height == 600)){ <BR>setActiveStyleSheet(CSS2); <BR>}else{ <BR>if ((screen.width == 1152) && (screen.height == 864)){ <BR>setActiveStyleSheet(CSS3); <BR>}else{ <BR>setActiveStyleSheet(CSS4); <BR>}}} <BR>} <BR>function setActiveStyleSheet(title){ <BR>document.getElementsByTagName("link")[0].href="style/"+title; <BR>} <BR>//--> <BR></script> 
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn