How to gracefully handle an iframe breaker?

I understand that there is no way to kill an iframe breaker ... However, I was wondering if there was a way to handle it competently.

So far, I have been able to detect it before exiting using <body onunload="function();">. I was wondering if it would be possible to prevent the iframe from loading or make it open in a new window, etc.

Cheers, Mickey

+3
source share
3 answers

In fact, you can really do what you really want to do is bust iframe buster . This method allows you to use onbeforeunload to switch the page back to yours, but indirectly because the browsers are too smart for you to set the URL to onbeforeunload. So instead, onbeforeunload sets an indicator variable to indicate that the URL has changed, and you periodically poll this variable using the setInterval procedure set when the page loads. While you are polling fast enough to catch a change in a variable, you can enter and change the page URL yourself. The trick is to change it to a page that returns 204, a special status that tells the browser to leave only one page.

, --. fooobar.com/questions/17202/..., , . - , ; , URL-, , , . URL- , , , .

. , Javascript, , iframe-busting. , , , . (, top [ "l" + "ocation" ] top.location).

, URL- Ajax- . (, iframe , Ajax ). 100% , , .

iframe .

+6

sandbox, HTML5, iframe. allow-top-navigation :

<iframe sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts"
src="foo.html"></iframe>
+2

iframe top.location? , .

, iframe , , , . , , . . Caja , . , (, XHR, , , ).

0

Source: https://habr.com/ru/post/1722244/


All Articles