Rod
Rod

Reputation: 15475

get to the label inside an iframe

Can someone please show me how to get to label1 inside the iframe via JavaScript?

WebForm1.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="calendar">
        <iframe src="WebForm2.aspx"></iframe>
    </div>
    </form>
</body>
</html>

WebForm2.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr><td class="default"><label id="label1">Label1</label></td></tr>
        </table>
    </div>
    </form>
</body>
</html>

Upvotes: 0

Views: 1506

Answers (1)

AmGates
AmGates

Reputation: 2123

Give the iframe an Id say for example

<iframe src="WebForm2.aspx" id="webForm" ></iframe>

Then in order to gain access to the field "lable1" you have give the following code

(document.getElementById("webForm")).contentWindow.document.getElementById("label1").innerHTML;

Hope this helps you

Upvotes: 3

Related Questions