检测iframe对象中的src /位置更改 [英] Detecting src/location change in a iframe object

查看:102
本文介绍了检测iframe对象中的src /位置更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向特定页面的iframe对象。例如,

 < iframe src =http://en.wikipedia.org/wiki/Special:Random> ;< / iframe中> 

每当iframe的位置发生变化时,我都希望有一个提醒,因为用户点击了一个链接它。



onLoad =alert(this.ContentWindow.location.href);不会产生任何结果。

执行 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 /位置更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆