2012-03-13 199 views
0

我弹出窗口,在弹出窗口中做了一些事情之后,我想返回主窗口。现在,我的弹出窗口出现在主窗口上的窗体。从弹出窗口调用主窗口

function checkForm() { 
//check all necessary things 
var varAmount =....; //which will get after process insides javascript 
window.location = 'myaction.action?amount='+varAmount ; 
} 

<form name="frmUpload" target="main">... 
<input type="button" class="button" value="Save" onclick="checkForm();"/> 
</form> 

我想金额值传递给我的动作太并希望返回到主窗口(并且这个过程完成后,要关闭弹出窗口,并调用myaction.actoin)。

虽然我打电话target="main",但它不会关闭弹出窗口并返回到主窗口。

+0

使用iframe并在上传时创建目标 – 2012-03-13 07:25:45

+0

弹出窗口中的'window.opener'将指向打开它的窗口或主窗口。 – kirilloid 2012-03-13 07:57:33

回答

0

如果你想指定的形式,你需要命名的脚本在主窗口主窗口主窗口:

window.name="main";

然后更改按钮提交,要么删除javascript或将检查到的onsubmit

function checkForm() { 
//check all necessary things 
var varAmount =....; //which will get after process insides javascript 
    if (...) return false; // cancel submit 
    return true; // allow submit 
} 


<form name="frmUpload" target="main" onsubmit="return checkForm(this)">... 
<input type="submit" class="button" value="Save" /> 
</form> 

如果你需要的JavaScript和按钮的地方是,你需要将其更改为

function checkForm() { 
    //check all necessary things 
    var varAmount =....; //which will get after process insides javascript 
    window.opener.location = 'myaction.action?amount='+varAmount 
    // OR using the name of the opener window 
    //window.open('myaction.action?amount='+varAmount,"main"); 
}