Automatically calls different CSS codes based on browser-Type Screen Resolution

Source: Internet
Author: User

Determine the resolution and browser

Rewrite the Code to make it the code that automatically calls different CSS to determine the screen resolution of the browser type.

Copy codeThe Code is 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 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 and the resolution is 1024*768,800*600,115 2*864, the css file name to be used.

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.

Var Other1024 = "";
Var Other800 = "";
Var Other1152 = "";
Var Otherother = "";

Fill in the quotation marks separately. When you use other browsers and the resolution is 1024*768,800*600,115 2*864, the css file name to be used.

No resolution, only browser judgment

Implement automatic calling of different CSS based on the browser type.

Copy codeThe Code is 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 other
SetActiveStyleSheet ("newsky.css ");
}
}

Function setActiveStyleSheet (title ){
Document. getElementsByTagName ("link") [0]. href = "style/" + title;
}
// -->
</SCRIPT>

Explanation:
If the browser is Internet Explorer, default.css is used.
If the browser is firefox, default2.css is used.
If the browser is another user, newsky.css is used.

Usage:
Put in
[Codes = xml] .

Only determine the resolution, not the browser

Copy codeThe Code is 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>

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.