美文网首页
iframe影响浏览器页面跳转

iframe影响浏览器页面跳转

作者: SimpleWrite | 来源:发表于2020-03-10 12:44 被阅读0次

    原因

    主要是由于浏览器history记录了iframe嵌入页面的路由信息,这个信息不论是iframe内的地址跳转,还是iframe src的切换,都会被记录,下面给出解决方案

    如不涉及iframe内地址的跳转

    <iframe ref="iframeWin" width="100%" height="100%" frameborder="0"></iframe>
    
      setIframe(src) {
          this.$refs.iframeWin.contentWindow.location.replace(src);
        },
    

    原理就是让iframe这个页面只被记录一次,从而实现“this.$router.go(-1)”正常跳转

    如涉及iframe内地址的跳转

    首先进入页面,记录history length

      created() {
        this.historyLength = window.history.length;
      }
    

    然后在页面返回时获取当前history length,相减即可得知需要返回多少个页面

      backClick() {
          let nowhl = window.history.length;
          let backCount = nowhl - this.historyLength + 1;
          this.$router.go(-backCount);
        }
    

    问题解决了,记录分享一下

    相关文章

      网友评论

          本文标题:iframe影响浏览器页面跳转

          本文链接:https://www.haomeiwen.com/subject/rtlwdhtx.html