• 请不要在回答技术问题时复制粘贴 AI 生成的内容
215503346
V2EX  ›  程序员

求助,给 iframe 添加返回按钮

  •  
  •   215503346 · Jul 5, 2019 · 3248 views
    This topic created in 2505 days ago, the information mentioned may be changed or developed.

    有一个跨域的 iframe,但是因为页面里面没有返回按钮,所以要给 iframe 外面添加一个返回按钮,这个该如何实现才能不影响到整个页面返回呢?

    6 replies    2019-07-05 17:50:17 +08:00
    santom
        1
    santom  
       Jul 5, 2019
    原生 js 去 iframe 里 append 一个 dom ?写好样式跟方法? 不太清楚 ,前几天刚好看到
    FenV
        2
    FenV  
       Jul 5, 2019
    改变 iframe src 地址就行吧
    BrbiwsFtd9zDGZqB
        3
    BrbiwsFtd9zDGZqB  
       Jul 5, 2019
    iframe 本身会在 history 中插入历史记录, 所以直接 history.go(-1) 就行.
    好像是这样, 前端不是很懂.
    215503346
        4
    215503346  
    OP
       Jul 5, 2019
    @a122996325 谢谢,是可以的,不过跨域无法操作里面的东西
    @FenV 谢谢,不过返回的话并不知道上一层是多少,跨域也获取不到
    @90d0n 谢谢,不过可能会导致点击到第一页再次点击会整个页面返回
    liuzhiyong
        5
    liuzhiyong  
       Jul 5, 2019 via Android
    @90d0n
    @215503346

    “点击到第一页再次点击会整个页面返回”

    也许你可以 IFRAME 首先加载自己的页面:my-domain/my-page.html 然后跳转到目标页面,只要你发现 IFRAME 回到了“ my-page.html ”,就知道 IFRAME 返回到尽头了。
    meepo3927
        6
    meepo3927  
       Jul 5, 2019
    如果 iframe 页面里的 js 不归你管,那基本无解。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5904 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 76ms · UTC 02:02 · PVG 10:02 · LAX 19:02 · JFK 22:02
    ♥ Do have faith in what you're doing.