提交表单,然后打开新窗口并关闭弹出窗口

时间:2013-11-12 15:10:02

标签: javascript jquery html ajax forms

我有一个出现在弹出窗口中的登录表单。我想写一些javascript(不确定我是否应该使用常规的js或Ajax),它将在提交表单后打开一个新的全尺寸窗口,然后关闭当前登录表单弹出窗口。我怎么能做到这一点?我知道我的问题是,在正常情况下,您在表单提交后无法执行任何其他操作,因为页面会刷新/重定向等。感谢您对我的问题提供任何帮助或解决方案。

我看过这个问题:Submit a form in a popup, and then close the popup但是无法理解它,或者它是否适用于我的问题。

形式:

<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" name="submitButton" />
              </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;
    }
    window.open('http://www.redlakewalleye.com/promotional/activation-form','_blank');
    theForm.submit();
    // window.close(); here?
    return false;
    }
//]]>
            </script>

        </form>

2 个答案:

答案 0 :(得分:0)

把它放在theForm.submit()之前:

var popup = window.open('http://www.redlakewalleye.com/promotional/activation-form','_blank');
theForm.onsubmit = function() {
    popup.close();
}

答案 1 :(得分:0)

在新窗口中,登录表单打开的那个,写下:

<script type="text/javascript">
if(window.opener != null) {
  window.opener.close(); // close login form
}
</script>