监听微信底栏返回事件,然后关闭窗口?

发布于 7 年前作者 yongjia4874 次浏览最后编辑 7 年前来自 ask

ios 微信监听popstate,然后关闭微信窗口,确实也会关闭,但是在关闭之前会返回一下上一个页面才关闭,请问如何解决?

pushHistory()

window.addEventListener('popstate', function (e) {
  var ua = navigator.userAgent.toLowerCase()
  if (ua.indexOf('micromessenger') > -1) {
    // eslint-disable-next-line no-undef
    WeixinJSBridge.call('closeWindow')
  } else if (ua.indexOf('alipay') > -1) {
    // eslint-disable-next-line no-undef
    AlipayJSBridge.call('closeWebview')
  } else {
    window.close()
  }
}, false)

function pushHistory () {
  var state = {
    title: 'title',
    url: '#'
  }
  window.history.pushState(state, 'title', '#')
}
1 回复
ping37
ping371 楼5 年前

不用push,用replace?