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?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
onload
eventlike
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
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.
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).