评论

微信h5支付使用iframe唤起原生微信支付的方法

微信h5支付是在浏览器或者webview中打开一条腾讯财付通的链接,然后使用weixin://唤起微信客户端执行支付。


这条链接里面的js代码默认如下:


我们从源码可以看出来,微信使用了top.location.href = 'xxx',兼容了在iframe中唤醒微信支付的场景

但是最新的ios12.4,在webview中屏蔽了第三方的iframe操作顶层页面的权限,官方说是基于安全性考虑。

我们查看iframe的相关说明,我们发现可以使用sandbox这条属性。

具体使用如下:

const iframe = document.createElement('iframe')
iframe.style.display = 'none'
iframe.setAttribute('src', url)
iframe.setAttribute('sandbox', 'allow-top-navigation allow-scripts')
document.body.appendChild(iframe)

亲测可用。

点赞 2
收藏
评论

1 个评论

  • A Girl Has No Name
    A Girl Has No Name
    2023-05-30

    用了这个方案但是还是不行

    2023-05-30
    赞同
    回复 1
    • 密斯特er龙
      密斯特er龙
      2023-07-21
      两个都是https就好了呀
      2023-07-21
      回复
登录 后发表内容