点击iframe中的事件

我正在尝试根据iframe中的当前url附加父网页的urliframe。

这一切都发生在同一个域上,所以我认为不存在任何安全问题。

编辑:

我的代码现在如下所示:

function locator_url() { var iframeUrl = alert(document.getElementById("dealer- locator").documentWindow.location.href); var iframeUrlSplit = iframeUrl.split('/locator/'); window.location.hash = '#' + iframeUrlSplit[1]; }; $(document).ready(function(){ document.getElementById("dealer-locator").contentWindow.onload = locator_url(); }); 

现在,iframe的默认src是http:// localhost / meade / locator / iframe所在的页面是http:// localhost / meade / dealerlocator /

该代码适用于初始页面加载,父URL将附加到localhost / meade / dealerlocator /#

但是,当我单击iframe内的链接时,即使iframe中的href值有效,父url也不会更改。

父url应该将其哈希更新为:

本地主机/梅亚德/ dealerlocator /#results_list.php?showonly = US&标签= US&拉链=距离= 10&状态=城市= NAME =

但那并没有发生。

我错过了什么?

你试过了吗:

 document.getElementById("dealer-locator").contentWindow.onload = locator_url; 

好吧,如果您需要在iframe中点击活动,那么您可以这样做:

 Car.com 

然后在父页面中调用locator_url() 。 使用加载事件也是如此(我的意思是,加载iframe上下文中发生的事件)。