Reputation: 89
This is the situation: I have on the same domain, an iframe inside my web site. currently, I have no immediate access to the iframe code as of deployment issues.
when the iframe loads, the code inside it detects something that triggers a redirection on the parent page. Temporarily, I want to remove it. I know I can use the onbeforeload, but a warning will be displayed every time the user click on a any link.
Is there a way I can detect the redirection? it happens before the main parent page is fully loaded.
I googled it a lot but still have no working solution.
Thanks!
Upvotes: 5
Views: 21482
Reputation: 5381
Try this:
<iframe align="left" src="http://stackoverflow.com/" sandbox=""></iframe>'
Upvotes: 2
Reputation: 18408
After reading the w3.org spec. I found another solution.
You can set sandbox=""
, which prevents the iframe frome redirecting. That being said it won't redirect the iframe either. You will lose the click essentially.
Example here: http://jsfiddle.net/ppkzS/1/
Example without sandbox: http://jsfiddle.net/ppkzS/
Upvotes: 6
Reputation: 2111
It's a bit of an ugly hack, but here's something that might work (I admit I don't know a whole lot about the workign of iframes). Grab the page you want to put into the iframe via javascript. Use javascript to parse through it until you get to the redirect code, and strip that redirect code out. Then put the result into the iframe. Ugly at best, but it seems like it might work.
Upvotes: -3
Reputation: 173
Use the onbeforeunload event to ask the user to leave this page or to stay.
<script>
window.onbeforeunload = function(){
return false; // This will stop the redirecting.
}
</script>
My answer is based on the answers from answers in Stackoverflow!!!
Upvotes: 0