0

So my initial issue is that whenever I click on a webpage (which loads an iFrame page within the page) and I interact with the iFrame, I have to click the back button multiple times in order to actually go back to the previous page I was on. I have found similar issues here which is pretty much what Im attempting, but I cannot use contentWindow.location.replace because of CORS/security restrictions.

What is an alternative to work around the CORs/security restrictions? I just need help using something else than contentWindow or can I use contentWindow somehow? to be able to not have more history added to the queue so the back button is only needed to be hit once instead of 2-3 times right now.

I am using

$('#myIFrame').setAttribute('src', `newUrl`);

in my code. So I figured that could be my solution, just cant figure out the contentWindow part. As I think the fix is the link I provided above. browser back acts on nested iframe before the page itself - is there a way to avoid it?

I have tried using the method up above but when I run it locally it gives me this error:Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'contentWindow')

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 05 '22 at 14:42
  • Updated it with some more clarity. – LocalProgrammer20 Dec 05 '22 at 14:48
  • Have you explord the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History)? Also, you can maybe have a go at saving the last visited page and add an event listener for a custom 'back' action? I have some suspicion that if the back button page is executed on the parent page, then you would actually go back; if that's not the case (really not sure!), then it means that your iframe is interacting with the session History, so you can just use that. – npetrov937 Dec 05 '22 at 14:59
  • Ill take a look at that for sure! – LocalProgrammer20 Dec 05 '22 at 15:28

0 Answers0