Iframe中的登录表单未加载

时间:2013-06-18 23:44:01

标签: javascript html iframe login

我在iframe中有一个登录表单。这是主页的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta content="text/html; charset=windows-1252" http-equiv="content-type">
        <script language="javascript">
            function SubmitForm() {
                document.getElementById('loginframe').contentWindow.document.getElementById('login').submit();
            }
        </script>
        <title>Login to Vote</title>
    </head>
     <body>
        <iframe id="loginframe" src="sasloginhandler.html"></iframe>
        <input onclick="SubmitForm()" value="Submit form" type="button">
    </body>
</html>

以下是“sasloginhandler.html”页面的代码:

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=windows-1252" http-equiv="content-type">
    <title>Login to Vote</title>
  </head>
  <body>
    <form action="https://moodle.standrews-de.org/login/index.php" method="post"
      id="login">
      <div class="loginform">
        <div class="form-input"> <input name="username" placeholder="Username"
            id="username"
            size="15"
            type="text">
        </div>
        <div class="form-input"> <input name="password" placeholder="Password"
            id="password"
            size="15"
            value=""
            type="password">
          <input id="loginbtn" value="Login" type="submit"> </div>
      </div>
      <div class="forgetpass"><a href="forgot_password.php">Forgotten your
          username or password?</a></div>
    </form>
  </body>
</html>

问题是,iframe内的提交按钮和iframe外的javascript提交按钮都没有做任何事情。我已经自己测试了iframe代码并且工作正常,因此它似乎是导致问题的iframe的一部分。但是,我不知道为什么会这样。

谢谢!

1 个答案:

答案 0 :(得分:0)

iframe中表单的ID为login,但您尝试使用loginform

document.getElementById('loginframe').contentWindow.document.getElementById('login').submit();