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
.
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.
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.
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> .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With