欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JS 仅允许微信客户端打开该页面

程序员文章站 2022-07-06 07:59:37
...
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
</head>
<body>
<script type="text/javascript">
    var ua = navigator.userAgent.toLowerCase();
    var isWeixin = ua.indexOf('micromessenger') != -1;
    var isAndroid = ua.indexOf('android') != -1;
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -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="css/weui.css">';
        document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
    }
</script>
</body>
</html>

 

效果图:
JS 仅允许微信客户端打开该页面
            
    
    博客分类: 境-JS 微信客户端userAgentUA仅允许用户代理 
 

 

 

 

 

 

 

 

 

 

  • JS 仅允许微信客户端打开该页面
            
    
    博客分类: 境-JS 微信客户端userAgentUA仅允许用户代理 
  • 大小: 11.1 KB