Skip to content

Using history.back() inside of an embedded <iframe> causes full page refresh on parent #3734

Description

@brian-mann

I have an application that embeds user content within an <iframe>. Calling history.back, history.forward, or history.go will always cause a full page refresh in the parent window.

Expected Behavior
When I navigate around within that <iframe> calling window.history.back() (inside of the <iframe>) should only change the window.location.href of the <iframe>. It should not affect the parent window at all.

Actual Behavior
Calling window.history.back() inside of an <iframe> causes a full page refresh in the parent window.

Addition Tidbits
In real Chrome and other browsers, when history entries are created by <iframes> going back / forward between those entries will only ever affect the actual <iframe> and will not leak across to parents.

Also, I have nodeIntegration disabled in the BrowserWindow instance.

Activity

  1. brian-mann commented on Dec 9, 2015

    @brian-mann
    Author

    Also it would be nice if it were publicly accessible from webContents to access the actual history array on the NavigationController instance. I read through the source and saw the array is never exposed.

    I'm currently patching the navigation controller object to do this:

    require("navigation-controller").prototype.getHistory = ->
     {history: @history, index: @currentIndex}

    As long as this is added prior to instantiating new BrowserWindow it'll get picked up as a function on the prototype here: https://github.com/atom/electron/blob/master/atom/browser/api/lib/web-contents.coffee#L55

    Now we can access that object:

    mainWindow.webContents.getHistory()
  2. bundyo commented on Jun 22, 2016

    @bundyo
    Contributor

    As a temporary fix until upgrading to a fixed version, one can replace the iframe's history.back() with the one of the containing window:

    iframeElement.contentWindow.history.back = window.history.back;
  3. TotallWAR commented on Jan 22, 2020

    @TotallWAR

    I have the same issue with native browser history API when i use IFRAME history.back func in SAFARI on IOS. And it doesn't work for first history event only. For example i open iframe window, click on button and into iframe i change history by pushState. Then if i try go back by history.back() method or by phone's system back button – page is reloaded. But if i change history INTO iframe multiple times, then history.back() works untill the moment i reach the first history change into iframe - then page is reloaded again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions