从弹出窗口调用主窗口

时间:2012-03-13 07:22:31

标签: javascript jsp javascript-events struts2

我弹出窗口,在弹出窗口后做了一些事情,我想回到主窗口。相反,应该出现在主窗口上的表单出现在我的弹出窗口中。

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>

我想将Amount值传递给我的操作,并希望返回主窗口(并在完成此过程后关闭弹出窗口)叫myaction.actoin)。

虽然我打电话给target="main",但它并没有关闭弹出窗口并返回主页。

1 个答案:

答案 0 :(得分: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");
}