【问题标题】:Javascript, how do I submit a form, then close the current window?Javascript,如何提交表单,然后关闭当前窗口?
【发布时间】:2013-11-12 05:27:00
【问题描述】:

我有一个弹出式登录表单。我希望表单提交,然后关闭该弹出窗口。我怎样才能做到这一点?该窗口当前设置为在函数返回之前关闭。在这种情况下,window.close() 去哪儿了?感谢您的帮助。

表格:

<form name="catseczoneform30738" onSubmit="return checkWholeForm30738(this)" method="post" action="https://redlakewalleye.worldsecuresystems.com/ZoneProcess.aspx?ZoneID=12695&Referrer={module_siteUrl,true,true}&OID={module_oid}&OTYPE={module_otype}">
            <div class="form">
              <div class="item">
                <label for="SZUsername">Username</label>
                <br />
                <input class="cat_textbox_small" type="text" name="Username" id="SZUsername" maxlength="255" />
              </div>
              <div class="item">
                <label for="SZPassword">Password</label>
                <br />
                <input class="cat_textbox_small" type="password" name="Password" id="SZPassword" maxlength="255" autocomplete="off" />
              </div>
              <div class="item">
                <input type="checkbox" name="RememberMe" id="RememberMe" />
                <label for="RememberMe">Remember Me</label>
              </div>
              <div class="item">
                <input class="cat_button" type="submit" value="Log in" />
                &nbsp;<a href="/_System/SystemPages/PasswordRetrieveRequest">Lost password?</a></div>
            </div>
            <script type="text/javascript" src="/CatalystScripts/ValidationFunctions.js"></script>
            <script type="text/javascript">
//<![CDATA[
    function checkWholeForm30738(theForm){var why = "";
    if (theForm.Username) why += isEmpty(theForm.Username.value, "Username");
    if (theForm.Password) why += isEmpty(theForm.Password.value, "Password");
    if (why != ""){alert(why);
        return false;
        }
    theForm.submit();
    window.open('http://www.redlakewalleye.com/promotional/activation-form','_blank');
    window.close();
    return false;
    }
//]]>
       </script>            
</form>

【问题讨论】:

    标签: javascript html forms


    【解决方案1】:

    如果可能的话,window.close() 应该包含在服务器对提交事件的响应中。如果您将 window.close() 作为表单提交的一部分包含在内,它将导致您的表单在提交实际发生之前关闭。

    【讨论】:

    • 我终于弄明白了。我最终编写了一个单独的函数来处理 window.open() 和 window.close() 方法。
    猜你喜欢
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 2012-01-26
    • 2013-09-01
    • 2012-08-14
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    相关资源
    最近更新 更多