I have a page like this...
and I want to do this...<
document.getElementById('mainContent').contentWindow.location.href
As Azmisov says iframe.src does the trick
<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>
Okay so you mean you have to access the URL of the parent from the child iframe?
$("#mainFrame").get(0).contentWindow.location
Does iframe.src not work? Or, are you trying to get the parent document? In that case, you can just use parent
.