Back button with iframe on page
See original GitHub issueBug report
When having a page with an <iframe>
with a dynamic src (ie based on a slug, eg /post/react
, and /post/angular
) the back button navigates the iframe itself, and not the main application, even when the iframe is not in focus.
The behavior does not occur when the iframe
does not have a src
, or has a static src
. The issue occurs both when the src
points to the same application or to an external site.
To Reproduce
I have created a somewhat minimal repo: https://github.com/ReinoutStevens/nextjs-backbutton
The iframe and the main page should always show the same slug, but this is not the case. Press one of the links, press the back button and notice how the iframe navigates back, but not the main application.
Initial visit:
Click link:
Go back:
System information
- OS: Ubuntu
- Browser: Chrome Version 75.0.3770.80 (Official Build) (64-bit). Also occurs in Firefox
- Version of Next.js: 9.0.2 and latest
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Back and forward buttons in an iframe
Use the window.history object. // For the current window window.history.back(); window.history.forward(); // For an iframe's window iframe.
Read more >[Solved] Brows back iFrame inside iFrame
I have an iframe in my html page and I have a button in the iframe. I want towhen press the button, iframe...
Read more >React, Iframes, and a Back-Navigation Bug
When you first click the back button in your browser, the iframe itself navigates backward, pointing to the embedded content that you saw...
Read more >javascript back buttons for iframe
Hey guys,. I've got an iframe that's pulling in cross-domain content, and I'm creating some back and forward navigation buttons to control this...
Read more >iframe back button problem - Forums
I'm using an iframe portlet in a liferay page. The iframe contain a web site in the same domain , so the urls...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue has been solved by placing
key={url}
on the iframe. Not 100% sure why or how this solves it, but the behavior is now the way we would expect it.This issue can be closed for me.
i agree with @nitzel, if not possible, this should, at least, be mentioned in Next.js doc (i guess in next/link doc) because fixing the issue with this “trick” is far from obvious