开发者

Get textbox within a form of an iframe

How can I get the textbox which is in a form and that form is in an iframe from javascript? The simplified code is:

<!-- other code --> 
    <div id="Login_Panel_Div">

        <iframe id="popupLoginScreen" src="login.jsp" name="popupContent">

            <html xmlns="http://www.w3.org/1999/xhtml">

            <head>
            </head>

            <body>

                <form id="loginForm" method="post" name="loginForm">
                    <h2>Login to your account</h2>                      

                    <label>Username:</label>

                    <input id="username" type="text" name="j_username">

                    <label>Password:</label>

                    <input id="password" type="password" name="j_password">

                    <button id="submitLoginBtn" value="Login" name="submitLoginBtn" type="submit">Login</button>
                </form>

            </body>

            </html>

        </iframe>

    </div>
<!-- other c开发者_开发技巧ode -->

If I want to get the input with id "txtbox" what should I do?

Thanks and Regards.


As xiao 啸 pointed me, the solution is:

var iframe = document.getElementById('popupLoginScreen');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var usernameTextBox = innerDoc.getElementById('username');
usernameTextBox.focus();

Requesting for thread close.

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜