监听微信底栏返回事件,然后关闭窗口?
发布于 5 年前 作者 yongjia 4700 次浏览 来自 问答

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 回复

不用push,用replace?

回到顶部