从弹出窗口调用主窗口

Call main window from the pop up window

本文关键字:窗口 调用      更新时间:2023-09-26

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

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.actin)。

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

如果您想将表单定位到主窗口,您需要在主窗口中的脚本中命名主窗口:

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");
}