我有一个表单,可以打开一个包含结果的新窗口。 为什么?因为新页面会计算数据并在屏幕上生成 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>
提交表单后,newpage.php 在新窗口中打开并生成 pdf 文件。当我返回到index.php(带有表单的页面)时,我希望刷新它,以便它将获得一个新的可用ID号。
我已经在按钮对象上尝试了 javascript 函数(onmouseup、onsubmit 等),但加载页面不起作用。为了测试代码,我输入了警报(“测试”);命令并运行!当加载页面或刷新当前页面时,它不起作用。
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>
关于javascript - <form>打开新窗口后如何刷新主页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125778/