Determine the resolution and browser
E. Qiang proposed that the code be improved to make it the code for automatically calling different CSS codes when determining the screen resolution of browser types.
The code is as follows:
| The code is as follows: |
Copy code |
<Script language = "JavaScript"> <! -- If (window. navigator. userAgent. indexOf ("MSIE")> = 1) { Var IE1024 = ""; Var IE800 = ""; Var IE1152 = ""; Var IEother = ""; ScreenWidth (IE1024, IE800, IE1152, IEother) } Else { If (window. navigator. userAgent. indexOf ("Firefox")> = 1) { // If the browser is Firefox Var Firefox1024 = ""; Var Firefox800 = ""; Var Firefox1152 = ""; Var Firefoxother = ""; ScreenWidth (Firefox1024, Firefox800, Firefox1152, Firefoxother) } Else { // If the browser is other Var Other1024 = ""; Var Other800 = ""; Var Other1152 = ""; Var Otherother = ""; ScreenWidth (Other1024, Other800, Other1152, Otherother) } } Function ScreenWidth (CSS1, CSS2, CSS3, CSS4 ){ If (screen. width = 1024) & (screen. height = 768 )){ SetActiveStyleSheet (CSS1 ); } Else { If (screen. width = 800) & (screen. height = 600 )){ SetActiveStyleSheet (CSS2 ); } Else { If (screen. width = 1152) & (screen. height = 864 )){ SetActiveStyleSheet (CSS3 ); } Else { SetActiveStyleSheet (CSS4 ); }}} } Function setActiveStyleSheet (title ){ Document. getElementsByTagName ("link") [0]. href = "style/" + title; } // --> </SCRIPT>
|
Explanation:
Var IE1024 = "";
Var IE800 = "";
Var IE1152 = "";
Var IEother = ""; fill in the quotation marks respectively. When you use IE, the resolution is 1024*768,800*600,115 2*864.
Var Firefox1024 = "";
Var Firefox800 = "";
Var Firefox1152 = "";
Var Firefoxother = "";
Fill in the quotation marks separately. When FF is used, the resolution is 1024*768,800*600,115 2*864.