微信授权PC扫码登陆,扫码成功后重定向被谷歌浏览器禁止

微信授权PC扫码登陆,扫码成功后重定向被谷歌浏览器禁止

说明

PC扫码登陆,手机扫码成功点击确定后,PC端没动静~~
在这里插入图片描述
重复多次后,胖胖仔细一看右上角。。重定向被禁止了!!!
在这里插入图片描述
由于二维码是iframe内嵌到页面中

<iframe style={{border:0,width:"100%",height:430,}} src={this.state.url} />

到这里就有必要提一嘴iframe中的sandbox属性,重点来了!

sandbox属性

如果被规定为空字符串(sandbox=""),sandbox 属性将会启用一系列对行内框架中内容的额外限制。
sandbox 属性的值既可以是一个空字符串(应用所有的限制),也可以是空格分隔的预定义值列表(将移除特定的限制)。
sandbox有很多属性,目前已经研究的属性有:""、 allow-same-origin、allow-top-navigation、 allow-forms、allow-scripts,接下来分别说下每个属性的作用。

  • sandbox=""
    表示应用allow-same-origin、allow-top-navigation、 allow-forms、allow-scripts等限制。
  • sandbox="allow-scripts"
    允许执行script脚本。
  • sandbox="allow-forms"
    允许提交表单。
  • sandbox="allow-top-navigation"
    允许 iframe 内容从包含文档导航(加载)内容。
  • sandbox="allow-same-origin"
    允许 iframe 内容被视为与包含文档有相同的来源。

解决方案及思路

在iframe标签中给sandbox设置allow-scripts以及allow-top-navigation属性

<iframe sandbox="allow-scripts allow-top-navigation" style={{border:0,width:"100%",height:430,}} src={this.state.url} />

OK!问题圆满解决!希望可以帮到看到此文的你()。我是胖胖,不瘦回150斤不改名字的男人!!!

发布了3 篇原创文章 · 获赞 13 · 访问量 1207

猜你喜欢

转载自blog.csdn.net/weixin_44272418/article/details/105320545
今日推荐