i have an aspx page containing开发者_JAVA技巧 following code
<body>
<script language="javascript" type="text/javascript">
function Hidee()
{
alert(window.frames["frame1"].document.getElementById("Label1").text);
}
</script>
<form id="form1" runat="server">
<div>
<iframe id="frame1" name="frame1" class="frame" frameborder="0" src="Default4.aspx"></iframe>
<a onclick="javascript:Hidee()" style="cursor: pointer">close</a>
</div>
</form>
</body>
in Default4 page i have a label with id Label1 when i click on close button i get undefined alert message
getElementById("Label1").text
An HTMLLabelElement doesn't have a text
property.
If it's a simple label that contains only a single Text node, you can say:
getElementById('Label1').firstChild.data
If it might contain more complicated text and element nodes, you'd have to iterate over them to pick up the text, or use the DOM Level 3 Core textContent
property, with backup for IE which doesn't support it:
var label= frames['frame1'].document.getElementById('Label1');
var text= ('textContent' in label)? label.textContent : label.innerText;
try with:
function Hidee() {
var ifr=document.getElementById("frame1"),
cd=ifr.contentDocument || ifr.contentWindow.document;
alert(cd.getElementById("Label1").innerHTML);
}
精彩评论