Is it possible to tell if the source of an iFrame has redirected the client to another page? And if so, tell what page the client got redirected to?
-
Possible duplicate: http://stackoverflow.com/questions/1759896/find-out-if-iframe-url-has-been-changed – Anderson Green Mar 25 '13 at 02:48
3 Answers
onload
event
like
<iframe src="http://www.mydomain/" onLoad="alert('fire');"></iframe>
The alert will pop-up whenever the location within the iframe has changed. check it out here also
Here is a question explaining how to get current location of an iframe
-
Ah, look at that! Great stuff, however ... I think this only applies to same-origin frames. – Michael McMillan Feb 12 '11 at 12:24
-
1
-
No, but this is not directly spying though - is it? It's not like I'm using JS to parse the response the server spits back. All I want to do is to check if the xmlhttpobject got a certain HTTP payback and then try to filter out what HTTP url it got redirect to. I know JS is restricted, but this should be possible. I had a look at Microsofts API for the IE proposal some other user posted, didn't quite get it to work though. – Michael McMillan Feb 17 '11 at 13:37
The src attribute won't change if the iframe navigates to a new page, but the location of the iframe's contentWindow will.
If you start the iframe in a page on your own domain you can use the iframes onload event to read iframe.contentWindow.location.href.
Use a try-block, and if it fails because of a cross domain call, you can return that the iframe is now in some remote site.
If it returns a value you can return the url on your site the iframe has navigated to.

- 102,654
- 32
- 106
- 127
Allright, so I've been fiddeling with this script for a while now and I think I've reached a conclusion which I think is worth sharing. Cross-domain is pretty strict, and as far as I know there is no way of telling what url the xmlhttprequest object got passed on to. I did however notice a solution on another site where they suggest using a hidden iFrame (I'm referring to the link in @ayush's answer).

- 133
- 2
- 7