Both judge the resolution and also judge the browser
Re-refine the code to make it a good judge of browser type screen resolution automatically calls different CSS code.
Copy Code code as follows:
<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 another
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 = && (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>
Explain:
var ie1024= "";
var ie800= "";
var ie1152= "";
var ieother= "";
Quotation marks are filled in separately, when the user uses IE and the resolution is 1024*768,800*600,1152*864 to use the CSS filename.
var firefox1024= "";
var firefox800= "";
var firefox1152= "";
var firefoxother= "";
Quotation marks are filled in separately, when the user uses FF and the resolution is 1024*768,800*600,1152*864 to use the CSS filename.
var other1024= "";
var other800= "";
var other1152= "";
var otherother= "";
Quotation marks are filled in separately, when the user uses another browser and the resolution is 1024*768,800*600,1152*864 to use the CSS filename.
Do not judge the resolution, only the browser
Implementation automatically invokes different CSS based on browser type.
Copy Code code as follows:
<script language= "JavaScript" >
<!--
if (Window.navigator.userAgent.indexOf ("MSIE") >=1)
{
If the browser is IE
Setactivestylesheet ("Default.css");
}else{
if (Window.navigator.userAgent.indexOf ("Firefox") >=1)
{
If the browser is Firefox
Setactivestylesheet ("Default2.css");
}else{
If the browser is another
Setactivestylesheet ("Newsky.css");
}
}
function Setactivestylesheet (title) {
document.getElementsByTagName ("link") [0].href= "style/" +title;
}
-->
</SCRIPT>
Explain:
If the browser is IE, call default.css
If the browser is Firefox, call Default2.css
If the browser is otherwise, call Newsky.css
Usage:
Placed in
[Codes=xml]Before you can.
Only judge the resolution, do not judge the browser
Copy Code code as follows:
<script language=javascript>
<!--
if (screen.width = 800)
{
document.write (' <link rel=stylesheet type= "text/css" href= "Css800.css" > ")
}
else {document.write (' <link rel=stylesheet type= ' text/css ' href= ' css1024.css ' > ')}
-->
</script>