HTML,JavaScript-每次使用POST方法提交表单时打开一个新选项卡

发布于 2025-02-02 17:45:47 字数 1533 浏览 2 评论 0原文

我有一个 html 选择字段,其中用户选择哪个表将从 mysql 数据库中显示他/她。

<form action = "tableOutput.php" method="post" name="frmTableSelect" target="_blank"> 
        <p>Select a table from the list</p>
        <select name="tableName" autofocus>
    <!-- here I load a list of tables from mySql. for simplicity let it be: -->
            <option>table 1</option>
        <option>table 2</option>
         <p><br><input name="submit" type="submit" id="knopka" value="show table"></p>
     </form>

这样,当用户键入按钮时,一个新的选项卡打开了所选表格打印的位置(我在“ tablecoutput.php”中对其进行处理) - 这很好。

但是用户需要返回第一个表单并选择另一个表格,该表应在 e 选项卡中打印,而它则在与第一个替换的同一选项卡中打印出来。它。 换句话说,我们需要能够打开带有输出的许多新选项卡。

我插入了这个JavaScript:

    <script>
      knopka.onclick = function() { 
        window.open("tableOutput.php")
      };
    </script>

现在,每次键入按钮时,一个选项卡都会打开,但是“ tableetutput.php”中的帖子方法不再起作用,因此我们在处理查询时会遇到错误。

如果我写

<script>
  knopka.submit = function() {   
    alert('inside javascript'); 
    window.open("tableOutput.php")
  };
</script>

什么都没有发生,即使警报也不会被执行。

请帮忙。

I have an html form with a select field where user selects which table we'll show him/her from the mySql database.

<form action = "tableOutput.php" method="post" name="frmTableSelect" target="_blank"> 
        <p>Select a table from the list</p>
        <select name="tableName" autofocus>
    <!-- here I load a list of tables from mySql. for simplicity let it be: -->
            <option>table 1</option>
        <option>table 2</option>
         <p><br><input name="submit" type="submit" id="knopka" value="show table"></p>
     </form>

Like this, when user hits the button, a new tab opens up where the selected table gets printed (I process it in "tableOutput.php") - this is fine.

But the user needs to return to the first form and select another table, that should be printed in another tab, whereas it gets printed in the same tab as the first one replacing it.
In other words, we need to be able to open many new tabs with output.

I inserted this javascript:

    <script>
      knopka.onclick = function() { 
        window.open("tableOutput.php")
      };
    </script>

Now a tab gets open every time one hits the button, but the POST method in "tableOutput.php" does not work anymore, so we get an error while processing the query.

If I write

<script>
  knopka.submit = function() {   
    alert('inside javascript'); 
    window.open("tableOutput.php")
  };
</script>

nothing happens, even the alert does not get executed.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2025-02-09 17:45:47

我很惊讶_blank重用相同的新标签,

您无法使用窗口。

尝试以下操作:

let cnt = 0;
document.querySelector("[name=frmTableSelect]").addEventListener("submit", function() {
  this.target=`win${cnt++}`;
})

I am surprised the _blank reuses the same new tab

You cannot use window.open to post to a new window/tab without a lot of code.

Try this:

let cnt = 0;
document.querySelector("[name=frmTableSelect]").addEventListener("submit", function() {
  this.target=`win${cnt++}`;
})
勿忘初心 2025-02-09 17:45:47

更改。

document.getElementById('knopka').onclick = function() {
alert('inside javascript');
window.open("tableOutput.php")
};

Change .submit to .onclick:

document.getElementById('knopka').onclick = function() {
alert('inside javascript');
window.open("tableOutput.php")
};

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文