Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent iframe from reloading the parent window

Is it possible to prevent an iframe from reloading the parent window?

The sandbox attribute without allow-top-navigation prevents redirection but doesn't prevent reloading.

PS: I need the sandbox to allow both allow-scripts and allow-same-origin.

like image 270
Diogo Cardoso Avatar asked Apr 01 '14 12:04

Diogo Cardoso


People also ask

How do I stop iframe from redirecting top level windows?

You can set sandbox="" , which prevents the iframe from redirecting. That being said it won't redirect the iframe either. You will lose the click essentially. Save this answer.

Does anyone use iframes anymore?

You see code iframes commonly used on websites that need to include external content like a Google map or a video from YouTube. Both of those popular websites use iframes in their embed code.

How do I use iframe tags?

Definition and UsageThe <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document. Tip: Use CSS to style the <iframe> (see example below). Tip: It is a good practice to always include a title attribute for the <iframe> .


1 Answers

See the findings here, it was a question asked previously. It experiments with stopping the page reload using preventDefault()

$(window).bind({
    beforeunload: function(ev) {
        ev.preventDefault();
    },
    unload: function(ev) {
        ev.preventDefault();
    }
});

Original Answer

Prevent refreshing / reloading a page with JavaScript

Note: This can be done using Javascript also with a bit more work.

like image 135
Dean Meehan Avatar answered Sep 18 '22 03:09

Dean Meehan