Window.open(“about:blank”)=> firefox阻止此站点打开弹出窗口

时间:2014-02-15 01:20:50

标签: php html firefox

当JQuery函数尝试在firefox中打开新页面时,会显示消息“firefox阻止此站点打开弹出窗口”。据我所知,基于Is window,open() impossible in firefoxLinks to local page do not work,这是一个本地问题,只是因为我试图从“localhost”访问我服务器中的文件。但是,当这个站点真正起作用时,其他人不会因为他们没有访问自己的服务器而遇到同样的问题。这种解释有意义吗?或者我错了,我必须处理这个问题?顺便说一句,因为我只改变了firefox的首选项,所以很容易在本地解决这个问题。我的担忧与其他人访问我的网站有关。

供参考,这是我的代码:

<?php
$theUsernameDaniel = "danielcajueiro";
$theUsernameMarcelo = "marcelopapini";
?>


<html>
    <head>
        <meta charset="utf-8" />
        <title>ControllingHiperlinks</title>
        <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>  


        <script>

            $(document).ready(function() {
                $("a.peoplePage").click(function(event) {
                    event.preventDefault();
                    var theUsername = $(this).data("username");
           //         alert(theUsername);
           //         event.preventDefault();
                    $.post('callmpeoplepage.php', {theUsername: theUsername}, function(data) {
                        var thePeoplePage = window.open("about:blank");
                        thePeoplePage.document.write(data);
                    });

                });
            });
        </script>        
    </head>
    <body>
        <a class="peoplePage" data-username="<?php echo $theUsernameDaniel ?>"  href=""> Daniel Cajueiro</a>
        <a class="peoplePage" data-username="<?php echo $theUsernameMarcelo ?>"  href="">Marcelo Cajueiro</a>


    </body>
</html>

callmpeoplepage.php是

<?php
$theUsername = $_POST['theUsername'];
echo $theUsername;

?>

2 个答案:

答案 0 :(得分:1)

除响应直接用户操作外,您无法打开弹出窗口。由于你延迟window.open直到帖子回复结束,它不再直接响应用户的点击,因此弹出窗口阻止程序将停止它。

每个人都会遇到这种情况,您无法改变行为。你可以尝试在提交帖子之前打开窗口,只在帖子返回时填写 - 只需将window.open行向上移动到$.post之前

答案 1 :(得分:1)

你可以这样写

let win = window.open("about:blank", "_blank");     

$.post('callmpeoplepage.php', {theUsername: theUsername}, function(data) {

            // if data is a valid url
            win.location.href = data;

 });
相关问题