admin 管理员组

文章数量: 887016

最近正在做一个微信服务号的项目,忽然接到需求,让这个页面只能在微信中访问,其他地方不可以。做出的效果是这样的

实现方式:在index.heml中加入script判断

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>test</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
    <script type=text/javascript>
      var useragent = navigator.userAgent;
      if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
        window.location.href = "/static/wxError.html";
      }

    </script>
  </body>
</html>

在static中放入wxError.html,一定要放在这里面,这个方法解决了Vue无法跳转html的问题。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
</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="https://res.wx.qq/open/libs/weui/0.4.1/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>

本文标签: 器中 页面 只能在 Vue