function getUrlState(URL) { var xmlhttp = new ActiveXObject("microsoft.xmlhttp"); xmlhttp.Open("GET", URL, false); try { xmlhttp.Send(); } catch (e) { } finally { var result = xmlhttp.responseText; if (result) { if (xmlhttp.Status == 200) { return true; } else { return false; } } else { return false; } } }
获取窗体可见范围的宽与高function getViewSize() { var de = document.documentElement; var db = document.body; var viewW = de.clientWidth == 0 ? db.clientWidth : de.clientWidth; var viewH = de.clientHeight == 0 ? db.clientHeight : de.clientHeight; return Array(viewW, viewH); }
获取移动设备最大化大小function getZoom() { var screenWidth = Math.abs(window.orientation) === 90 ? Math.max(screen.height, screen.width) : Math.min(screen.height, screen.width); if (this.isAndroidMobileDevice() && !this.isNewChromeOnAndroid()) { screenWidth = screenWidth / window.devicePixelRatio; } var FixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport; var FixViewPortsExperimentRunning = FixViewPortsExperiment && (FixViewPortsExperiment === "New" || FixViewPortsExperiment === "new"); if (FixViewPortsExperimentRunning) { return screenWidth / window.innerWidth; } else { return screenWidth / document.body.offsetWidth; } }
判断是否安卓移动设备访问function isAndroidMobileDevice() { return /android/i.test(navigator.userAgent.toLowerCase()); }
判断是否苹果移动设备访问function isAppleMobileDevice() { return /iphone|ipod|ipad|Macintosh/i.test(navigator.userAgent.toLowerCase()); }
判断是否为数字类型function isDigit(value) { var patrn = /^[0-9]*$/; if (patrn.exec(value) == null || value == "") { return false; } else { return true; } }
是否是某类手机型号// 用devicePixelRatio和分辨率判断 const isIphonex = () => { // X XS, XS Max, XR const xSeriesConfig = [ { devicePixelRatio: 3, width: 375, height: 812 }, { devicePixelRatio: 3, width: 414, height: 896 }, { devicePixelRatio: 2, width: 414, height: 896 } ]; // h5 if (typeof window !== "undefined" && window) { const isIOS = /iphone/gi.test(window.navigator.userAgent); if (!isIOS) return false; const { devicePixelRatio, screen } = window; const { width, height } = screen; return xSeriesConfig.some( item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height ); } return false; };
判断是否移动设备function isMobile() { if (typeof this._isMobile === "boolean") { return this._isMobile; } var screenWidth = this.getScreenWidth(); var fixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport; var fixViewPortsExperimentRunning = fixViewPortsExperiment && fixViewPortsExperiment.toLowerCase() === "new"; if (!fixViewPortsExperiment) { if (!this.isAppleMobileDevice()) { screenWidth = screenWidth / window.devicePixelRatio; } } var isMobileScreenSize = screenWidth < 600; var isMobileUserAgent = false; this._isMobile = isMobileScreenSize && this.isTouchScreen(); return this._isMobile; }
判断吗是否手机号码function isMobileNumber(e) { var i = "134,135,136,137,138,139,150,151,152,157,158,159,187,188,147,182,183,184,178", n = "130,131,132,155,156,185,186,145,176", a = "133,153,180,181,189,177,173,170", o = e || "", r = o.substring(0, 3), d = o.substring(0, 4), s = !!/^1\d{10}$/.test(o) && (n.indexOf(r) >= 0 ? "联通" : a.indexOf(r) >= 0 ? "电信" : "1349" == d ? "电信" : i.indexOf(r) >= 0 ? "移动" : "未知"); return s; }
判断是否是移动设备访问function isMobileUserAgent() { return /iphone|ipod|android.*mobile|windows.*phone|blackberry.*mobile/i.test( window.navigator.userAgent.toLowerCase() ); }
判断鼠标是否移出事件function isMouseOut(e, handler) { if (e.type !== "mouseout") { return false; } var reltg = e.relatedTarget ? e.relatedTarget : e.type === "mouseout" ? e.toElement : e.fromElement; while (reltg && reltg !== handler) { reltg = reltg.parentNode; } return reltg !== handler; }
判断是否Touch屏幕function isTouchScreen() { return ( "ontouchstart" in window || (window.DocumentTouch && document instanceof DocumentTouch) ); }
判断是否为网址function isURL(strUrl) { var regular = /^\b(((https?|ftp):\/\/)?[-a-z0-9]+(\.[-a-z0-9]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|asia|coop|aero|[a-z][a-z]|((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d))\b(\/[-a-z0-9_:\@&?=+,.!\/~%\$]*)?)$/i; if (regular.test(strUrl)) { return true; } else { return false; } }
判断是否打开视窗function isViewportOpen() { return !!document.getElementById("wixMobileViewport"); }
加载样式文件