繁体   English   中英

打开子窗口时不提交父窗口形式

[英]not submit form of parent window when child window is open

我写这段代码..但是当子窗口打开时我不想提交父窗口的表单

<script language="javascript">   
 function popwindow(page) { 
OpenWin = this.open(page,"CtrlWindow","top=80,left=100,screenX=100,screenY=80,width=600,height=400,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes,resizable=yes");
OpenWin.focus();
return false;
}
</script>

使用false设置全局变量,并在打开子窗口/新窗口时将其设置为true。 在窗口关闭时,将该变量再次设置为false。 在表单上提交检查该变量状态。 如果为假,请提交,否则不提交。 为此使用window.open/window.close方法。

使用此代码:

的HTML

<form method="get" action="">
    <button value="open" id="open">Open</button>
    <input type="submit" value="submit" />
</form>

JS(jQuery 1.9)

$(function(){
    var customWindow = false;
    $('#open').click(function(e){
        e.preventDefault();
        customWindow = true;
        customWindow = window.open('http://www.google.com', "","menubar=1,resizable=1"); 
        customWindow.focus(); 
    });

    $('[type="submit"]').on('click', function(e){
        e.preventDefault();
        if(customWindow.closed || !customWindow) {
            alert('form submit');
        } else {
            alert('please close the child window');
        }
    });
});

看到这个小提琴

窗口具有closed属性,因此只需检查OpenWin.closed。

http://www.w3schools.com/jsref/prop_win_closed.asp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM