【问题标题】:How to refresh the main page after the <form> opens a new window?<form> 打开新窗口后如何刷新主页?
【发布时间】:2016-03-21 16:22:34
【问题描述】:

我有一个表单,它会打开一个包含结果的新窗口。 为什么?因为新页面会计算数据并在屏幕上生成 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 号。

我在按钮对象(onmouseup、onsubmit 等)上尝试了 javascript 函数,但加载页面不起作用。为了测试代码,我输入了一个警报(“test”);命令并运行!在加载页面或刷新当前页面时,它不起作用。

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

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

感谢您的宝贵时间。

【问题讨论】:

    标签: javascript html forms page-refresh


    【解决方案1】:

    试试这个;)

    <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>
    

    【讨论】:

      【解决方案2】:

      试着把它放在表单标签里:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多