mogutouer
V2EX  ›  问与答

vue router 在页面有 iframe 的情况下,如何返回真的上一页?

  •  
  •   mogutouer · Aug 23, 2017 · 4193 views
    This topic created in 3183 days ago, the information mentioned may be changed or developed.
    是这样的,我有一个 webapp,内有客服的功能,点进去就像 app 里用 webview 来嵌入一个第三方的客服系统,vue 里我用了 iframe 来嵌入。
    页面有一个 nav bar,就像原生 app 的 navbar,我想让这个 nvabar 上的返回,是返回到进入客服页面的上一页。

    现在出现的问题是,如果被嵌入的第三方客服内进行了跳转,那么用 vue router 的返回,其实跟浏览器一样,是在操作 iframe 内的 history,导致如果客服的 iframe 里有 link 跳转页面并点了多次 url 变更,那么用户要点很多次返回才能真正的返回。


    目前想到 2 个解决方案不知可否实现( google 了很久找不到什么是否可以实现)

    1.有没有办法完全不用浏览器的 history ?就像原生 app 嵌入 webview 一样,app 的 push 和 back 操作与嵌入页面无任何关系。
    2.能否像原生 app 的 nav 一样,得到 history 之前每一个页面的历史记录?这样至少可以根据记录用 go(-?) 到某个之前的页面。
    3 replies    2017-08-23 23:20:29 +08:00
    pubby
        1
    pubby  
       Aug 23, 2017
    回退前把<iframe>清理掉
    readonly
        2
    readonly  
       Aug 23, 2017
    iframe 里面的链接用 location.replace 跳转,这样就只会有一个历史记录了
    mogutouer
        3
    mogutouer  
    OP
       Aug 23, 2017
    @readonly #2 第三方的跳转没法控制,有一些是直接 header 跳的根本来不及操作
    @pubby #1 我试试是否可行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6175 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 02:04 · PVG 10:04 · LAX 19:04 · JFK 22:04
    ♥ Do have faith in what you're doing.