我想创建一个按钮,打开一个包含用户名称的新标签。但在Chrome中它总是阻止弹出窗口。有没有办法在不启用弹出窗口的情况下执行此操作?
<div class="box">
<form action="" method="post">
<input type="text" name="meno" class="form-control" placeholder="Nick">
<input type="submit" name="submit" class="tlacitko" value="Submit">
</form>
<?php
if($_POST){
$nick = $_POST['meno'];
$hlasovat = "<script>window.open('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";
echo $hlasovat;
unset($_POST);
}
?>
</div>
答案 0 :(得分:1)
如果您希望在提交HTML表单时在新窗口/选项卡中打开,可以使用:
<form action="" method="post" target="_blank">
而不是
<form action="" method="post">
为了让您的代码使用这种技术,您可能还需要执行以下操作:
$hlasovat = "<script>window.location.href = 'https://czech-craft.eu/vote?id=16942&user=$nick' </script>";
或
$hlasovat = "<script>window.location.assign('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";
或
$hlasovat = "<script>window.location.replace('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";
而不是
$hlasovat = "<script>window.open('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";