• vue、jquery 监听浏览器回退事件,然后返回到指定页面


    vue:

    methods: {
        //返回按钮指定到首页去
        goBack() {
          this.$router.push({ path: "/" });
        },
      },
      //页面销毁时,取消监听
      destroyed() {
        window.removeEventListener("popstate", this.goBack, false);
      },
      mounted() {
        //监听浏览器返回
        if (window.history) {
          history.pushState(null, "", document.URL); //这里有没有都无所谓,最好是有以防万一
          window.addEventListener("popstate", this.goBack, false); // 回退时执行goback方法
        }
      },

    jquery:

    //处理回退
            if (window.history && window.history.pushState) {
                history.pushState(null, null, document.URL);
                window.addEventListener('popstate', function () {
                    history.pushState(null, null, document.URL);
                    //跳转首页
                    this.window.location = $get("<%=returnUrl.ClientID %>").value;
                });
            }
  • 相关阅读:
    HTML5 模板推荐
    OpenCV初探
    微信开放框架-UCToo
    ProFTPD 初探
    移动开发者服务平台-友盟
    线程原理理解
    JVM参数及性能调优
    GC——垃圾回收
    JVM内存模型
    php常用 随机数
  • 原文地址:https://www.cnblogs.com/xiaoxiaomini/p/16400432.html
Copyright © 2020-2023  润新知