我有一个这样的页面...
<div>
<iframe id="mainContent">
<iframe id="littleBox">
</div>我想这么做。
$(".someButton").live('click', function() {
alert(/*The URL That the Main Frame is ON*/);
});我找到了这个:$("#mainFrame").get(0).location.href,但它不能工作...
另外,我需要它来返回当前的url,所以如果有人在它周围导航,应该返回他们所在的当前页面。
发布于 2010-09-15 09:08:01
好的,那么你的意思是你必须从子iframe访问父进程的URL?
$("#mainFrame").get(0).contentWindow.location发布于 2010-09-14 09:41:16
iframe.src不工作吗?或者,您是否正在尝试获取父文档?在这种情况下,您可以只使用parent。
发布于 2010-09-14 11:02:46
正如阿兹米索夫所说,iframe.src做到了这一点
<head runat="server">
<title>iframe Test</title>
<script type="text/javascript">
function ShowURLs() {
var control = document.getElementById("mainContent");
alert("iframe source = " + control.src);
alert("this page = " + location.href);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="someButton" value="Click Me" onclick="ShowURLs()" />
<div>
<iframe id="mainContent" src="Test.aspx" />
<iframe id="littleBox" />
</div>
</div>
</form>
</body>https://stackoverflow.com/questions/3705594
复制相似问题