So I\'ve read about the HTML5 sandbox property and I understand that if I want to prevent an iframe redirect its parent window I can use the sandbox
property leavin
With HTML5 the iframe sandbox attribute was added.
At the time of writing this works on Chrome, Safari, Firefox and recent versions of IE and Opera but does pretty much what you want:
<iframe src="url" sandbox="allow-same-origin"></iframe>
Browser Compatibility
Some Useful links
You can use the onbeforeunload
property and determine if you wan to redirect or not.
Here is the docs page for it
Basically what I would try is this:
allow-top-navigation
, to the iframeonbeforeunload
property of the iframe that calls the function that adds the sandbox attribute (be sure not to return anything because a dialog will pop-up)This should work because the request is made in the iframe first, and then we can prevent it from carrying over to our top level window.
Another thing you should check is if you maybe left out the allow-forms
option, which can cause what you are describing.
Please let me know if any of this worked.