今天遇到了有些浏览器会拦截微信登录得跳转,导致不能登录

google了一下发现是跟iframe有关系,解决办法是把引入得微信js改成自己引入,并添加d.sandbox=”allow-scripts allow-top-navigation allow-same-origin”
完整代码

1
2
3
<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; e += a.style ? "&style=" + a.style : "", e += a.href ? "&href=" + a.href : "", d.src = e, d.frameBorder = "0", d.allowTransparency = "true", d.scrolling = "no", d.width = "300px", d.height = "400px",d.sandbox="allow-scripts allow-top-navigation allow-same-origin"; var f = b.getElementById(a.id); f.innerHTML = "", f.appendChild(d) } a.WxLogin = d }(window, document);
</script>