0
  • I have a js function, when I give async as false it opens as new window,
  • but when i give async as true its showing as pop up
  • I need to make the code as async as true, but it should open as new window not as pop up
  • can you guys tell me how to Make a asynchronous request so that the new window willnot load as a popup.
  • is there any alternate method for window.open
  • providing my code below

        //
        debugger;
        Ext.Ajax.request({
            async: false,
            url: sports.util.Utils.getContextPath() + '/tabClicks.do',
    
  • What's the difference between a pop up and a new window? – Barmar Sep 17 '15 at 16:21
  • Are you talking about whether the popup blocker complains about it? – Barmar Sep 17 '15 at 16:22
  • http://stackoverflow.com/questions/2572333/google-chrome-window-open-workaround - I think you may be referring to the window without the toolbar as a 'popout', you have little control over this with JavaScript in chrome. – MrBizle Sep 17 '15 at 16:27
  • You can open the window in the original event and relocate it when you're ready. – Halcyon Sep 17 '15 at 16:28
  • @barmar yes i am talking about popup complaints –  Sep 17 '15 at 16:47
  • @Halcyon can you update in my code, its confusing –  Sep 17 '15 at 17:18

3 Answers3

1

Your code is a little bit weird so it's hard to make the adjustment properly but this is gist of it:

showNewWindow: function(menu) {
    var me = this,
        newWindowId = sports.util.Utils.randomString(12);

    //
    // Make a synchronous request so that the new window will
    // not load as a popup.
    //
    debugger;
    var popup = sports.util.Utils.openNewWindow('', 'menu', {}, null, null, newWindowId);
    Ext.Ajax.request({
        async: false,
        url: sports.util.Utils.getContextPath() + '/tabClicks.do',
        params: {
            oldWindowId: sports.util.Utils.getWindowName(),
            newWindowId: newWindowId
        },
        success: function() {
            popup.location.href = "/desktop/main";
        },
        scope: me
    });
},
Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

Popup blockers try to tell when a window is being opened in direct response to a user action or spontaneously by the application. The way they probably do this is by checking whether the function that called window.open() was run in response to a user-triggered event like a mouse click.

When you perform a synchronous AJAX request, the function that was triggered by the mouse click is still running when the response arrives and the success function calls window.open. So it's considered to be a user-requested window, not a popup.

When you use asynchronous AJAX, the click handler is no longer running when the success function runs. The asynchronous call to window.open is considered spontaneous by the browser, so it blocks it.

I don't think there's any way around this, because anything you could do could also be used by everyone else to get around popup blockers, and they would be useless.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • thanks for your reply, will this can be achieved using Halcyon and user3612048 solutions –  Sep 17 '15 at 17:19
  • I was just about to add to my answer a solution similar to @Halcyon's answer. Give that a try. – Barmar Sep 17 '15 at 17:22
  • It should be `popup.document.location.href` – Barmar Sep 17 '15 at 19:18
  • I updated my code and tested, but still i am getting the error Uncaught TypeError: Cannot read property 'document' of undefined –  Sep 17 '15 at 19:31
0
function openNewWin(name) {
      $.ajax({
          async: false,
          type: 'POST',
          url: 'your url',
          success: function () {
               window.open(name);
          },
          async: false
      });
  }
GOPI
  • 1,042
  • 8
  • 30
  • name is youe page url which you want to open and that passed from code behind – user7510054 Feb 03 '17 at 07:57
  • 2
    You should really add some explanation as to why this should work - you can also add code as well as the comments in the code itself - in its current form, it does not provide any explanation which can help the rest of the community to understand what you did to solve/answer the question.This is especially important for an older question and the questions that already have answers. – ishmaelMakitla Feb 03 '17 at 08:20