2 Star 5 Fork 7

青ツ玉/常用封装函数

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bom.js 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2019-11-13 15:15 +08:00 . ‘’
/** 常用BOM操作 */
function getQueryString() { /** 获取当前页面的请求参数 */
let qs = (location.search.length > 0 ? location.search.substring(1) : "");
let args = {};
let items = qs.length ? qs.split("&") : [];
let item = null;
let name = null;
let value = null;
for (let i = 0, len = items.length; i < len; i++) {
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if (name.length) {
args[name] = value;
}
}
return args;
}
function isScrollBottom() { /** 检测滚动条是否滚动到底部 */
if (document.body.scrollHeight - document.body.scrollTop <= window.screen.availHeight) {
return true;
}
return false;
}
function isWhatBrowser() { /** 判断打开网页的是什么浏览器,移动端还是pc端 */
/** @return 'wechat' 'ios' 'android' 'pc' */
const u = navigator.userAgent
const browser = {
ie: u.indexOf('Trident') > -1, // IE内核
opera: u.indexOf('Presto') > -1, // Presto内核
chrome: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
firefox: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
safari: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
wechat: u.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'
}
if(browser.mobile) { // 移动端浏览器
if(browser.wechat) return 'wechat' // 微信内打开
if(browser.ios) return 'ios' // ios浏览器打开
if(browser.android) return 'android' // 安卓浏览器打开
}
return 'pc' // pc端浏览器
}
export default {
getQueryString,
isScrollBottom,
isWhatBrowser
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuchunling/common_encapsulation_functions.git
git@gitee.com:wuchunling/common_encapsulation_functions.git
wuchunling
common_encapsulation_functions
常用封装函数
master

搜索帮助