question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Back button with iframe on page

See original GitHub issue

Bug 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: Screenshot from 2019-07-25 16-06-26

Click link: Screenshot from 2019-07-25 16-06-39

Go back: Screenshot from 2019-07-25 16-06-50

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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
ReinoutStevenscommented, Aug 3, 2019

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.

1reaction
bertrand-rivierecommented, Mar 31, 2021

Would there be a way to warn about iframes with variable src and no key configured when transpiling? I’d like to save others from spending a lot of time on this problem…

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found