/*========================================= 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