使用JQuery / Javascript访问iFrame URL

我有这样一个页面……

我想这样做……

  $(".someButton").live('click', function() { alert(/*The URL That the Main Frame is ON*/); }); 

我发现了这个: $("#mainFrame").get(0).location.href ,但它不起作用……

此外,我需要它来返回当前的URL,所以如果有人在其周围导航它应该返回它们所在的当前页面。

好的,你的意思是你必须从子iframe访问父级的URL?

 $("#mainFrame").get(0).contentWindow.location 

iframe.src不起作用吗? 或者,您是否想要获取父文档? 在这种情况下,您可以只使用parent

正如Azmisov所说,iframe.src可以解决问题

  iframe Test    
 document.getElementById('mainContent').contentWindow.location.href