简体   繁体   English

确认php条件后打开多个窗口

[英]Open multiple windows after verify php condition

i have the file 1.html: 我有文件1.html:

.....


 <script src="/libs/jquery-1.3.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    var url0='{$url0}';
    var url1='{$url1}';
    var url2='{$url2}';
    var url3='{$url3}';
    var OPEN_ON = false;
    openurls= function(){
    if(confirm('Opens all?') && OPEN_ON == false){
                    OPEN_ON = true;
    $.ajax({<br/>
        type: "POST",
        url: "a1.php",
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            success = true;

        },
        error: function(msg) {

        }
    })

    if(success) { 
     window.open(url0)
     window.open(url1)
    window.open(url2)
    window.open(url3) 
    }


                 setTimeout("location.reload(true);",3000) 

                    OPEN_ON = false
                }
                return false

    }

Question is: 问题是:
How do I send url0, url1, url2 and url3 to the file a1.php and there after checking some conditions to send them back. 在检查了一些条件后,如何将url0,url1,url2和url3发送到文件a1.php以及在那里。 enter code here

You just need to put those window.open() calls inside the "success:" callback function. 您只需要将那些window.open()调用放入 “ success:”回调函数中。

Now, once you do that, you're going to find that the new windows don't actually open. 现在,一旦执行此操作,您将发现新窗口实际上并未打开。 The browsers are going to block them because they look like aggressive popup ads. 浏览器将阻止它们,因为它们看起来像是激进的弹出广告。 Because those window.open calls are happening in a context other than a direct user-initiated event (like a button click), they'll be blocked. 由于那些window.open调用发生在上下文中,而不是直接由用户启动的事件(如按钮单击),因此它们将被阻止。 That said, here's what your "success" function should look like: 就是说,这是您的“成功”函数的外观:

$.ajax({<br/>
    type: "POST",
    url: "a1.php",
    data: { url0: url0, url1: url1, url2: url2, url3: url3 },
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      window.open(url0);
      window.open(url1);
      window.open(url2);
      window.open(url3);
    },
    error: function(msg) {

    }
})

That will "work" as the window.open() calls will be made, but it won't "work" in that you won't actually get popups. 这样将“起作用”,因为将进行window.open()调用,但是由于实际上不会弹出窗口,因此它不会“起作用”。 You have to make it such that user activity (a "click" somewhere) makes the windows open, not an XMLHttpRequest state change. 您必须使用户活动(在某处“单击”)使窗口打开,而不是使XMLHttpRequest状态更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM