javaScript笔记

判断当前页面是否在微信浏览器中打开

2016-12-14  本文已影响0人  史天王

微信官方的做法如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
</head>
<body>
<script type="text/javascript">
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
if (!isWeixin) {
document.head.innerHTML = '<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/connect/zh_CN/htmledition/style/wap_err1a9853.css">';
document.body.innerHTML = '<div class="page_msg"><div class="inner"><span class="msg_icon_wrp"><i class="icon80_smile"></i></span><div class="msg_content">
请在微信客户端打开链接
</div></div></div>';
}
</script>
</body>
</html>

文/4456lyn(简书作者)
原文链接:http://www.jianshu.com/p/d365fb356e2c
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

效果如下:

jianshu_1.pic.jpg
上一篇下一篇

猜你喜欢

热点阅读