Kumar
Kumar

Reputation: 105

How to extract iframe's redirect url?

I searched alot but didn't find(or I didn't understand those solutions) what im looking for. I want to extract redirect url from an iframe. For example, I embedded xyz.com in an iframe and now when iframe gets loaded on client browser, it gets redirected to example.com/.

I want to extract redirected url, i.e example.com/

Thanks

Upvotes: 0

Views: 549

Answers (1)

webpopular.net
webpopular.net

Reputation: 179

if your iframe is on the same domain, you can select the iframe, select the contents of iframe, select what has your redirect url, use window.location to redirect:

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var redirect = innerDoc.getElementById('redirectURL').innerHTML;
window.location = redirect;

if it's not, you won't be able to get the contents due to cross site scripting

Upvotes: 1

Related Questions