html,每次使用Post方法提交表单时打开一个新选项卡



我有一个htmlselect字段,用户从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>

就像这样,当用户点击按钮时,会打开一个新选项卡,其中打印所选的表(我在"tableoutput .php"中处理它)—这很好。

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

我插入了这个javascript:

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

现在每次点击按钮都会打开一个选项卡,但是在"tableOutput.php"不再工作,所以在处理查询时得到一个错误。

如果我写

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

什么都没发生,即使是警报不被执行

请帮助。

我很惊讶_blank重复使用相同的新选项卡

你不能使用窗口。open topost到一个新的窗口/选项卡,不需要很多代码。

试试这个:

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

将.submit更改为。onclick:

. getelementbyid("knopka")。Onclick = function() {alert('内部javascript ');window.open("tableOutput.php")};

相关内容

最新更新