H5 关闭浏览器 监听 窗口关闭 或刷新窗口

H5 关闭浏览器

function win_close () {
  // 判断是否支持WeixinJSBridge 微信环境
  if (typeof WeixinJSBridge !== 'undefined') {
    WeixinJSBridge.call('closeWindow')// 微信自带的关闭窗口WeixinJSBridge.call("closeWindow")
  } else {
    // H5 环境
    if (navigator.userAgent.indexOf('MSIE') > 0) {
      if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
        window.opener = null
        window.close()
      } else {
        window.open('', '_top')
        window.top.close()
      }
    } else if (navigator.userAgent.indexOf('Firefox') > 0) {
      window.location.href = 'about:blank '
    } else {
      window.opener = null
      window.open('', '_self', '')
      window.close()
    }
  }
}

监听 窗口关闭 或刷新窗口

var ua = navigator.userAgent.toLowerCase()
let isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1
    if (isAndroid) {
    // 安卓   window.onbeforeunload
= function (e) { e = e || window.event // 处理函数 return '' } } else {
    // ios window.addEventListener(
'pagehide', myUnloadHandler, false) function myUnloadHandler () { // 处理函数 } }
原文地址:https://www.cnblogs.com/wukongz/p/13570346.html