10

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.

Chris Peters
  • 17,918
  • 6
  • 49
  • 65
carriwitchet
  • 121
  • 1
  • 1
  • 10

1 Answers1

5

Use correct case in "ContentWindow", it's supposed to be "contentWindow".

<iframe src="your initial URL" onload="alert(this.contentWindow.location.href)" /> 

works.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136