JS script that invokes CSS code based on browser and resolution

Source: Internet
Author: User
<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)
{
file://if the browser is Firefox
var firefox1024= "";
var firefox800= "";
var firefox1152= "";
var firefoxother= "";
ScreenWidth (Firefox1024,firefox800,firefox1152,firefoxother)
}else{
file://if the browser for 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 = && (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;
}
File://-->
</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

The following code should be prepared E.qiang the proposal. Implementation automatically invokes different CSS based on browser type.

Code:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
file://如果浏览器为IE
setActiveStyleSheet("default.css");
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
file://如果浏览器为Firefox
setActiveStyleSheet("default2.css");
}else{
file://如果浏览器为其他
setActiveStyleSheet("newsky.css");
}
}
   function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
file://-->
</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: Put it in front of

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.