1. <i id='uki5R'><tr id='uki5R'><dt id='uki5R'><q id='uki5R'><span id='uki5R'><b id='uki5R'><form id='uki5R'><ins id='uki5R'></ins><ul id='uki5R'></ul><sub id='uki5R'></sub></form><legend id='uki5R'></legend><bdo id='uki5R'><pre id='uki5R'><center id='uki5R'></center></pre></bdo></b><th id='uki5R'></th></span></q></dt></tr></i><div id='uki5R'><tfoot id='uki5R'></tfoot><dl id='uki5R'><fieldset id='uki5R'></fieldset></dl></div>
      <legend id='uki5R'><style id='uki5R'><dir id='uki5R'><q id='uki5R'></q></dir></style></legend>

      <small id='uki5R'></small><noframes id='uki5R'>

      • <bdo id='uki5R'></bdo><ul id='uki5R'></ul>
      <tfoot id='uki5R'></tfoot>

      在 jQuery ajax 成功回调中创建时弹出窗口被阻止

      Popup blocked when created in jQuery ajax success callback(在 jQuery ajax 成功回调中创建时弹出窗口被阻止)
        <tbody id='UoZhW'></tbody>
    2. <tfoot id='UoZhW'></tfoot>

      <legend id='UoZhW'><style id='UoZhW'><dir id='UoZhW'><q id='UoZhW'></q></dir></style></legend>
            • <bdo id='UoZhW'></bdo><ul id='UoZhW'></ul>

              <i id='UoZhW'><tr id='UoZhW'><dt id='UoZhW'><q id='UoZhW'><span id='UoZhW'><b id='UoZhW'><form id='UoZhW'><ins id='UoZhW'></ins><ul id='UoZhW'></ul><sub id='UoZhW'></sub></form><legend id='UoZhW'></legend><bdo id='UoZhW'><pre id='UoZhW'><center id='UoZhW'></center></pre></bdo></b><th id='UoZhW'></th></span></q></dt></tr></i><div id='UoZhW'><tfoot id='UoZhW'></tfoot><dl id='UoZhW'><fieldset id='UoZhW'></fieldset></dl></div>

                <small id='UoZhW'></small><noframes id='UoZhW'>

              1. 本文介绍了在 jQuery ajax 成功回调中创建时弹出窗口被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Google Chrome 似乎阻止了我通过 jQuery 创建的弹出窗口.经过一番调查,在 ajax 调用的成功事件中调用 window.open 似乎是一个问题.有没有解决的办法?我的 jQuery ajax 调用返回要打开的 URL.所以我有点卡住了.

                Google Chrome seems to be blocking a popup I am creating via jQuery. After some investigation, it appears to be an issue with calling window.open in the success event of an ajax call. Is there a way around this? My jQuery ajax call returns the URL to be opened. So I am bit stuck.

                如果我将 window.open 放在 ajax 调用之外,它会起作用;但是,在内部(即在成功事件中)它被阻止了.我认为这与 CONTEXT 有关,但我不确定.

                It works if I place the window.open outside the ajax call; but, inside (i.e. in the success event) it is blocked. I think it is something to do with CONTEXT but I am unsure.

                这是我所拥有的:

                     window.open("https://www.myurl.com");  // OUTSIDE OF AJAX - no problems 
                                                            // with popup
                
                     $.ajax({
                        type: "POST",
                        url: "MyService.aspx/ConstructUrl",
                        data: jsonData,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {
                            // Normally loads msg.d which is the url returned from service
                            // static url below is for testing
                            window.open("https://www.myurl.com");  // THIS IS BLOCKED
                        },
                        error: function(msg) {
                            // alert(error);
                        }
                    });
                

                推荐答案

                只需在成功回调中打开新窗口即可:

                Simply open the new window in the success callback:

                 $.ajax({
                    type: "POST",
                    url: "MyService.aspx/ConstructUrl",
                    data: jsonData,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        window.open("https://www.myurl.com"); 
                    },
                    error: function(msg) {
                        //alert(error);
                    }
                });
                

                请注意,您可能必须为此将 $.ajax 的异步选项设置为 false,否则可能会在收到响应之前评估 $.ajax 调用之后的代码.

                Note you might have to set $.ajax's async option to false for that, otherwise the code following the $.ajax call could be evaluated before the response is received.

                这篇关于在 jQuery ajax 成功回调中创建时弹出窗口被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                Difference between fetch, ajax, and xhr(fetch、ajax 和 xhr 之间的区别)
                How to use JSONP on fetch/axios cross-site requests(如何在 fetch/axios 跨站请求中使用 JSONP)
                Django returns 403 error on POST request with Fetch(Django 使用 Fetch 对 POST 请求返回 403 错误)
                Open page in new window without popup blocking(在新窗口中打开页面而不阻止弹出窗口)
                Javascript Confirm popup Yes, No button instead of OK and Cancel(Javascript 确认弹出窗口是,否按钮而不是确定和取消)

                <small id='ssSJY'></small><noframes id='ssSJY'>

                  <tbody id='ssSJY'></tbody>
                  <bdo id='ssSJY'></bdo><ul id='ssSJY'></ul>

                      <tfoot id='ssSJY'></tfoot>
                      • <legend id='ssSJY'><style id='ssSJY'><dir id='ssSJY'><q id='ssSJY'></q></dir></style></legend>
                        <i id='ssSJY'><tr id='ssSJY'><dt id='ssSJY'><q id='ssSJY'><span id='ssSJY'><b id='ssSJY'><form id='ssSJY'><ins id='ssSJY'></ins><ul id='ssSJY'></ul><sub id='ssSJY'></sub></form><legend id='ssSJY'></legend><bdo id='ssSJY'><pre id='ssSJY'><center id='ssSJY'></center></pre></bdo></b><th id='ssSJY'></th></span></q></dt></tr></i><div id='ssSJY'><tfoot id='ssSJY'></tfoot><dl id='ssSJY'><fieldset id='ssSJY'></fieldset></dl></div>