前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >js判断手机浏览器操作系统及微信浏览器的方法

js判断手机浏览器操作系统及微信浏览器的方法

作者头像
Vicsh
发布2018-05-16 11:06:14
3.5K0
发布2018-05-16 11:06:14
举报
文章被收录于专栏:落叶大大落叶大大

今天用到的代码,一并奉上。

js判断手机系统并跳转 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //alert(navigator.userAgent); window.location.href ="apple.htm"; } else if (/(Android)/i.test(navigator.userAgent)) { //alert(navigator.userAgent); window.location.href ="android.htm"; }else{ window.location.href ="xxx/tablet.htm"; };

js判断微信浏览器并提示

<script type="text/javascript"> function is_weixin() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } } var isWeixin = is_weixin(); var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight; function loadHtml(){ var div = document.createElement('div'); div.id = 'weixin-tip'; div.innerHTML = '<p><img src="http://photo.101rc.com/weixin/live_weixin.png" alt="微信打开"/></p>'; document.body.appendChild(div); } function loadStyleText(cssText) { var style = document.createElement('style'); style.rel = 'stylesheet'; style.type = 'text/css'; try { style.appendChild(document.createTextNode(cssText)); } catch (e) { style.styleSheet.cssText = cssText; //ie9以下 } var head=document.getElementsByTagName("head")[0]; //head标签之间加上style样式 head.appendChild(style); } var cssText = "#weixin-tip{position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80); width: 100%; height:100%; z-index: 100;} #weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%;}"; if(isWeixin){ loadHtml(); loadStyleText(cssText); } </script>

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-03-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档