【问题标题】:Window.open("about:blank") => firefox prevented this site from opening a pop-up windowWindow.open("about:blank") => firefox 阻止此站点打开弹出窗口
【发布时间】:2014-03-14 13:45:40
【问题描述】:

当 JQuery 函数尝试在 firefox 中打开新页面时,会显示消息“firefox 阻止此站点打开弹出窗口”。据我了解,基于Is window,open() impossible in firefoxLinks to local page do not work 这是一个本地问题,仅在我试图从“本地主机”访问服务器中的文件时才会发生。但是,当这个站点真正运行时,其他人不会因为没有访问自己的服务器而遇到同样的问题。这种解释有意义吗?或者我错了,我必须处理这个问题?顺便说一句,这个问题很容易在本地解决,因为我只更改了 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;

?>

【问题讨论】:

  • 什么动作触发了window.open?
  • @Collin-Grady 请查看我的更新。

标签: php html firefox


【解决方案1】:

您无法打开弹出窗口,除非是响应用户的直接操作。由于您延迟 window.open 直到帖子回复完成,它不再直接响应用户的点击,因此弹出窗口拦截器将停止它。

这将发生在每个人身上,你无法改变行为。您可以尝试在提交帖子之前打开窗口,并且仅在帖子返回时才填写 - 只需将 window.open 队列移至 $.post 之前的位置即可

【讨论】:

    【解决方案2】:

    你可以这样写

    let win = window.open("about:blank", "_blank");     
    
    $.post('callmpeoplepage.php', {theUsername: theUsername}, function(data) {
    
                // if data is a valid url
                win.location.href = data;
    
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多