When a page corresponds to more than one CSS style file, we can import different CSS files based on the value of the address bar's parameters:
functiongetcss () {varLinknode = document.createelement ("link"); Linknode.setattribute ("rel", "stylesheet"); Linknode.setattribute ("Type", "Text/css"); if(GetQueryString (' from ') = = ' LK ') {Linknode.setattribute ("href", "css/prod_details_lk.css"); Console.log (111); }Else{//default import of Push-guest CSSLinknode.setattribute ("href", "css/prod_details_tk.css"); } document.head.appendChild (Linknode); };functiongetquerystring (name) {varReg =NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); varr = Window.location.search.substr (1). Match (REG); if(r!=NULL)returnUnescape (r[2]);return NULL;} Getcss ();
The following is from the I ' m QQ official website JS Code (https://im.qq.com/index.shtml), it with the browser device is different and open the corresponding page, so as to achieve the response style.
if(window.location.protocol=== "http:") {Window.location.replace (' Https://im.qq.com/index.shtml '); } varT0 =NewDate (); varOS =function() { varUA =navigator.useragent, Iswindowsphone=/(?: Windows Phone)/. Test (UA), Issymbian=/(?: SymbianOS)/.test (UA) | |Iswindowsphone, Isandroid=/(?: Android)/. Test (UA), Isfirefox=/(?: Firefox)/. Test (UA), Ischrome=/(?: chrome| Crios)/. Test (UA), Istablet=/(?: ipad| PlayBook)/.test (UA) | | (Isandroid &&!/(?: Mobile)/.test (UA)) | | (Isfirefox &&/(?: Tablet)/. Test (UA)), Isphone=/(?: IPhone)/.test (UA) &&!Istablet, IsPc=!isphone &&!isandroid &&!Issymbian; return{istablet:istablet, Isphone:isphone, Isandroid:isandroid, ISPC:ISPC}; }(); varGetsearch =function(name) {varReg =NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); varr = window.location.search.substring (1). Match (REG); if( !!r) {returnUnescape (r[2]); } return NULL; }; varSearchstr =Window.location.search, Hashstr=Window.location.hash; varVIEWPC = Getsearch ("VPC"); if(!viewpc && (os.isandroid | |Os.isphone)) {Location.replace (' Http://im.qq.com/immobile/index.html ' +searchstr+hashstr); }Else if(Os.istablet) {location.replace (' Http://im.qq.com/qqhd/' +searchstr+hashstr); }
Importing unused CSS files and displaying unused HTML pages on different devices