I am using an iframe in my page to display content from an external website, but sometimes the iframe redirects a whole page to a new location, and this causes unwanted things on my website.
Is it possible to find the page where the iframe is going to redirect my website? if so, give me a basic example on how to find this redirection address. I would like to open this address in a new tab, because information from this address may be useful for my users.
http://www.b.com [ abstract code ] :
if(somethingHappens) window.top.location.href = "http://google.com";
http://www.a.com [ abstract code ]:
<!-- code -->
<iframe src="http://www.b.com"></iframe>
<!-- code -->
Expected Result [ abstract code ]:
if(pageIsBeingRedirected) {
stopRedirection();
var url = findRedirectAddres(); // expected : http://google.com
window.open(url, "_blank");
return;
}
If you are redirecting to external sites then you can’t track the iframe URL but you can get only what’s in the iframe
srcvalue.Example,
http://jsfiddle.net/CDwQK/1/
What you are looking will work only if
parentandiframeshares same domain. It won’t work if different domains.