如何在<form>打开一个新窗口后刷新主页

How to refresh the main page after the <form> opens a new window?

本文关键字:新窗口 一个 窗口 主页 刷新 form      更新时间:2023-09-26

我有一个表单,可以打开一个包含结果的新窗口。为什么?因为新页面会计算数据并在屏幕上生成 PDF。所以在简单形式中,代码(假设 index.php)看起来像这样:

<?
//loads data and finds the next availiable numerical (autoincrease) ID. e.g. $nextid=103;
?>
<form action=newpage.php method=post target=_blank>
Next Availiable ID: <input type=text name=id value="<?=$nextid?>"><br/>
Your Name: input type=text name=thename maxlength=64><br/>
<button type=submit>Go!</submit>
<form>

提交表单后,新页面.php将在新窗口中打开并生成 pdf。当我返回索引时.php(带有表单的页面)我希望刷新它,以便它获得一个新的可用 ID 号。

我已经在按钮对象(鼠标向上,提交等)上尝试了javascript函数,但是加载页面不起作用。为了测试代码,我输入了一个警报("测试");命令,它运行!在加载页面或刷新当前页面时,它不起作用。

onclick="loadUrl('http://somesite.com')"也不起作用。

现在我用 newpage.php 中的控制代码绕过了它,但我希望刷新页面以便 PHP 读取数据库。有什么想法吗?

谢谢你的时间。

试试这个;)

<form action="newpage.php" method="post" target="_blank" onsubmit="javascript: setTimeout(function(){location.reload();}, 1000);return true;">
  Next Availiable ID: <input type="text" name="id" value="<?= $nextid ?>"><br/>
  Your Name: <input type="text" name="thename" maxlength="64"><br/>
  <button type="submit">Go!</button>
</form>

尝试将其放入表单标签中:

onsubmit = "document.location = 'http://somewebsite.com'"