简体   繁体   English

浏览器正在阻止 Javascript window.open

[英]browser is blocking Javascript window.open

I want to create a button that opens a new tab with the user's name.我想创建一个按钮,用用户名打开一个新选项卡。 But in Chrome it always block the popup window.但在 Chrome 中它总是阻止弹出窗口。 Is there way to do this without enabling popup windows?有没有办法在不启用弹出窗口的情况下做到这一点?

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

If you want your HTML form to open in a new window/tab when submitted you can use:如果您希望 HTML 表单在提交时在新窗口/选项卡中打开,您可以使用:

<form action="" method="post" target="_blank">

instead of代替

<form action="" method="post">

For your code to work using this technique you will probably also need to do something like:为了让您的代码使用这种技术工作,您可能还需要执行以下操作:

$hlasovat = "<script>window.location.href = 'https://czech-craft.eu/vote?id=16942&user=$nick' </script>";

or或者

$hlasovat = "<script>window.location.assign('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";

or或者

$hlasovat = "<script>window.location.replace('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";

instead of代替

$hlasovat = "<script>window.open('https://czech-craft.eu/vote?id=16942&user=$nick') </script>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM