ajax打开新窗口防止被浏览器阻止问题

1 打开新窗口,window.open(),这本身并不会被浏览器阻止,但是放在ajax方法中,弹出新窗口就被阻止了,如下:

  function mfopen(id, name) {
        jQuery.ajax({
            type: "GET",
            dataType: "text",
            url: "UserLogin.aspx?method=init",
            success: function (msg) {
                var Json = eval("(" + msg + ")");
                if (Json.result == "100") {
                    if ( Json.isagtuser != "0") {  
                        jErpPopup("没有资格", 'no.aspx', 415, 90, function () { });
                    }
                    else {
                        var cid = id;
                        var cname = name;
                        var url = 'chuli.aspx?id=' + cid + '&name=' + escape(cname)  + '&num=Math.Random()' + '';
                        window.open(url);
                    }
                }
                else {
                    jErpPopup("您还没有登录,请先登录", 'Login.aspx?fun=pingjiaagent2', 410, 180, function () { });
                }
            }
        });
        }
       
  

2,ajax默认异步,修改为同步执行,可以解决弹出新窗口被浏览器阻止的问题,如下:

 function mfopen(id, name) {
        jQuery.ajax({
            type: "GET",
            async:false,
            dataType: "text",
            url: "UserLogin.aspx?method=init",
            success: function (msg) {
                var Json = eval("(" + msg + ")");
                if (Json.result == "100") {
                    if ( Json.isagtuser != "0") {  
                        jErpPopup("没有资格", 'no.aspx', 415, 90, function () { });
                    }
                    else {
                        var cid = id;
                        var cname = name;
                        var url = 'chuli.aspx?id=' + cid + '&name=' + escape(cname)  + '&num=Math.Random()' + '';
                        window.open(url);
                    }
                }
                else {
                    jErpPopup("您还没有登录,请先登录", 'Login.aspx?fun=pingjiaagent2', 410, 180, function () { });
                }
            }
        });
        }

 

 

posted on 2013-04-07 11:01  judy_ma0605  阅读(1038)  评论(1编辑  收藏  举报

导航