I have an iframe object pointing to a specific page. For example,
<iframe src="http://en.wikipedia.org/wiki/Special:Random"></iframe>
I want to have an alert whenever the location of the iframe changes because the user has clicked a link inside it.
Doing onLoad="alert(this.ContentWindow.location.href);"
yields nothing.
Doing onLoad="alert(this.src);"
yields the initial src (../wiki/Special:Random) no matter what the user has clicked.
The user will stay within the same domain, so the Same Origin policy is not violated.
Use correct case in "ContentWindow", it's supposed to be "contentWindow".
<iframe src="your initial URL" onload="alert(this.contentWindow.location.href)" />
works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With