JS Get the Phone browser type, modify the CSS file's class value

Source: Internet
Author: User

/*========================================= function: Get browser type =========================================*/function Getbrowser () {varType ="PC"    varUA =navigator.userAgent.toLowerCase (); /*Navigator is a built-in object in the HTML DOM that contains information about the browser. UserAgent is the Navigator property method that returns the value of the user-agent header of the server sent by the client. The effect is to return what browser the current user is using,*/    if(Ua.indexof ('Android') >-1) {type="Android"        varStart_index = Ua.indexof ('Android'); varVersion = Ua.substring (Start_index, Start_index + A); Version= Version.replace ("/"," "); //below Android 4.4 version        if(Version <"Android 4.4")        {            params. lowversion =true; Updateclass ("Common.css",". Modal-dialog", Function (cssrule) {cssRule.style.top="2%"; CssRule.style.marginTop="0px";            }); /*. modal-dialog {top:45%;                  left:50%;                  width:300px;                  height:500px;                  Position:absolute;                margin: -120px 0px 0px-150px; }            */        }    }    Else if(Ua.indexof ('iphone') >-1|| Ua.indexof ('ipad') >-1) {type="iOS"; }    returntype;}/** * Modify file Style * @param fileName file name * @param className Style name * @param method callback function, modify the style within the callback function*/function Updateclass (FileName, ClassName, method) {varStyleSheet =NULL, Cssrule =NULL; //document.stylesheets: Gets all CSS styles for the page <link rel= "stylesheet" type= "Text/css" href= ". /.. /.. /css/common.css ">     for(vari =0, Len = document.styleSheets.length; i < Len; i++) {        if(Document.stylesheets[i].href! =NULL&& Document.stylesheets[i].href.indexof (fileName) >=0) {StyleSheet=Document.stylesheets[i];  Break; }    }    if(StyleSheet = =NULL)    {        return; }//Stylesheet.cssrules get all styles for common.css files     for(vari =0, Len = styleSheet.cssRules.length; i < Len; i++)    {        if(Stylesheet.cssrules[i].selectortext && stylesheet.cssrules[i].selectortext.indexof (className) >=0) {Cssrule=Stylesheet.cssrules[i]; /*Cssrule is:. modal-dialog {top:45%;                  left:50%;                  width:300px;                  height:500px;                  Position:absolute;                margin: -120px 0px 0px-150px; }            */method (Cssrule); return; }    }}

JS Get the Phone browser type, modify the CSS file's class value

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.