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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题