2014-02-15 84 views
0

当jQuery函数尝试在Firefox中打开新页面时,消息“firefox阻止该站点打开弹出窗口呈现窗口“。据我所知,基于Is window,open() impossible in firefoxLinks to local page do not work这是一个本地问题,只发生,因为我试图从“本地主机”访问我的服务器中的文件。但是,当这个网站真的有效时,其他人就不会因为没有访问他们自己的服务器而出现同样的问题。这种解释是否有意义?或者我错了,我必须处理这个问题?顺便说一下,在本地解决这个问题很容易,因为我只是改变了Firefox的偏好。我的担心与访问我网站的其他人有关。Window.open(“about:blank”)=> 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; 

?> 
+0

触发window.open的操作是什么? –

+0

@ Collin-Grady请参阅我的更新。 – DanielTheRocketMan

回答

1

你不能打开一个弹出除了响应直接用户操作。由于您延迟了window.open,直到回复完成,它不再直接响应用户的点击,因此弹出窗口阻止程序将停止它。

这会发生在每个人身上,而且你无法改变行为。您可以在提交帖子之前尝试打开窗口,并且只在帖子返回时填充该窗口 - 只需将window.open一行向上移动到$.post

相关问题