提交表单,关闭弹出窗口并刷新父页面

时间:2012-09-26 02:44:00

标签: javascript php html

popup1.php

<script>
function pepz(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 
</script>

<a href="" onclick="pepz('<?php echo"popup2.php"; ?>', 'myPop1',465,410)"><?php print"Click"; ?></a></td>

popup2.php

<form action='#' method='post'>
<input type='submit'>
<form>

在弹出窗口中单击表单中的提交按钮后,我需要关闭弹出窗口以及调用弹出窗口刷新的父页面。

我做错了什么?谢谢你:D

2 个答案:

答案 0 :(得分:2)

简单的方法是将以下属性添加到提交按钮:

onClick="window.parent.location.reload();window.close()"

答案 1 :(得分:0)

从您的父页面调用此弹出窗口:

window.open("foo.html","windowName", "width=400,height=400,scrollbars=no");

使用函数提交表单。控制窗口关闭事件并使其刷新父页面。

<form action='#' method='post' name='my_form'>
<input type="button" value="Upload"  onclick="closeSelf();"/>
</form>
<script>
  window.onunload = refreshParent;
  function refreshParent() {
    window.opener.location.reload();
  }
  function closeSelf(){
    document.forms['my_form'].submit();
    window.close();   
  }
</script>