微信二维码登录扫码报错

当我进行扫描二维码登陆时,出现Unsafe attempt to initiate navigation for frame with origin  http://localhost:3000  from frame with URL  https://open.weixin.qq.com/connect/qrconnect?appid=wx67cfaf9e3ad31a0d\\\\&scope=snsapi_login\\\报错

原因是:浏览器监测到了iframe中存在不安全的链接正在尝试进行导航,需要设置iframe的sandbox属性

解决方法:

<script src="https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
  <script>
    !function (a, b, c) {
      function d (a) {
        var c = "default"
        a.self_redirect === !0 ? c = "true" : a.self_redirect === !1 && (c = "false")
        var d = b.createElement("iframe"),
          e = "https://open.weixin.qq.com/connect/qrconnect?appid=" + a.appid + "&scope=" + a.scope + "&redirect_uri=" + a.redirect_uri + "&state=" + a.state + "&login_type=jssdk&self_redirect=" + c + '&styletype=' + (a.styletype || '') + '&sizetype=' + (a.sizetype || '') + '&bgcolor=' + (a.bgcolor || '') + '&rst=' + (a.rst || '')
        e += a.style ? "&style=" + a.style : "",
          e += a.href ? "&href=" + a.href : "",
          d.src = e,
          d.frameBorder = "0",
          d.allowTransparency = "true",
          d.sandbox = "allow-scripts allow-top-navigation allow-same-origin", //重点
          d.scrolling = "no",
          d.width = "300px",
          d.height = "400px"
        var f = b.getElementById(a.id)
        f.innerHTML = "",
          f.appendChild(d)
      }
      a.WxLogin = d
    }(window, document);
  </script>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值