在HTML页面中查找加载到iFrame中的当前网址 [英] Find current url loaded into iFrame inside html page

查看:265
本文介绍了在HTML页面中查找加载到iFrame中的当前网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的HTML页面,在其中有一个iFrame.以下是此代码段.

I am having a simple HTML page, inside which i have an iFrame. below is the code snippet for this.

<html>
<head></head>
<body>
<input id="currentSrc" type="text" value="" />
<iframe id="myframe" src="http://www.bing.com">
<p>your browser doesn''t support iframes
</p></iframe>
</body>
</html>



现在我想要的是,当用户单击iframe或在iframe内进行任何导致框架加载新页面的活动时,文本框"currentSrc"应填充iframe内页面的当前URL.

我试图用$("myframe").attr("src")获取url,但是它总是返回"bing.com" ...在谷歌搜索后,我发现了两个属性,如contentWindow和contentDocument,即使它们包含正确的url但由于跨域访问而给出权限被拒绝"例外.我想知道是否有任何方法可以使用jquery,json或jsonp来解决此问题.

请帮助,任何指导将不胜感激.预先感谢.



now what i want is, that when ever user clicks or does any activity inside the iframe which causes the frame to load a new page then the text box "currentSrc" should get populated with current url of the page inside iframe.

i have tried getting the url with $("myframe").attr(''src'') but it always returns "bing.com"... After googling i found two properties like contentWindow and contentDocument which even though contain proper urls but gives "Permission denied" exception because of cross domain access. I wonder if there is any way may be using jquery, json or jsonp to get a work around this.

Please help, any guidance will be highly appreciated. Thanks in advance.

推荐答案

("myframe").attr("src"),但它始终返回"bing.com" ...在谷歌搜索后,我发现了两个属性,例如contentWindow和contentDocument,尽管它们包含正确的url,但由于跨域访问而给出了"PermissionPermission"例外.我想知道是否有任何方法可以使用jquery,json或jsonp来解决此问题.

请帮助,任何指导将不胜感激.预先感谢.
("myframe").attr(''src'') but it always returns "bing.com"... After googling i found two properties like contentWindow and contentDocument which even though contain proper urls but gives "Permission denied" exception because of cross domain access. I wonder if there is any way may be using jquery, json or jsonp to get a work around this.

Please help, any guidance will be highly appreciated. Thanks in advance.


更改位置并重新加载框架内容时,属性"src"不会更改(因此,我确认了您的问题).而是尝试使用框架的contentDocument.您需要处理框架的事件"onload".

—SA
The property "src" does not change when you change location and reload the frame content (so I confirm your problem). Instead, try to use contentDocument of the frame. You need to handle the frame''s event "onload".

—SA


这篇关于在HTML页面中查找加载到iFrame中的当前网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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