问题描述
我有一个指向特定页面的iframe对象。例如,
执行 onLoad =alert(this.src);产生初始src(../wiki/特殊:随机)无论用户点击了什么。
用户将停留在同一个域中,因此不违反相同原点策略。
解决方案在ContentWindow中使用正确的大小写,它应该是contentWindow。
< iframe src =您的初始URLonload =alert(this.contentWindow.location.href)/>
的作品。
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.
这篇关于检测iframe对象中的src /位置更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!