dtgta48604
2014-02-15 01:20
浏览 166
已采纳

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

When the JQuery function tries to open a new page in firefox, the message "firefox prevented this site from opening a pop-up window" is presented. As I understand based on Is window,open() impossible in firefox and Links to local page do not work this is a local problem that only happens because I am trying to access a file in my server from the "localhost". However, when this site will be realy working, other people will not have the same problem just because they are not accessing their own server. Does this interpretation make sense? Or I am wrong and I have to deal with this problem? By the way, it is easy to solve locally this problem since I have only change the preferences of firefox. My worries are related with the other people accessing my web site.

For reference, this is my code:

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

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

?>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtxw20878 2014-02-15 02:18
    已采纳

    You cannot open a popup except in response to a direct user action. Since you delay the window.open until the post reply finishes, it is no longer directly in response to the user's click, and therefore the popup blocker will stop it.

    This will happen for everyone, and you cannot change the behavior. You could try opening the window before you submit the post, and only filling it in when the post returns - just move the window.open line up one to just before $.post

    打赏 评论

相关推荐 更多相似问题