0

Possible Duplicate:
window.open(url) different behavior - same code, different timing

I'll let my code snippet explain the issue I'm seeing.

function myFunction() {
    window.open('http://www.yahoo.com');  // --> this opens a new tab on my browser
    Ext.Ajax.request({
        url: 'PHP function call',
        success: function(response) {
            window.open('http://www.yahoo.com');  // --> this opens a new window, not tab
        }
    });
}

This is very strange. From researching this issue, I understand there currently exists no way to force a browser tab to open instead of a browser window. That being said, I'm still wondering if there's any workaround. The way my app is designed, every time I call window.open() a tab is opened except for this one case and therefore my clients find it very annoying. Any insight would be greatly appreciated.

In addition to Justin's suggestion below I also tried the following:

function myFunction() {
    var myWin = window;
    myWin.open('http://www.yahoo.com');  // --> this opens a new tab on my browser
    Ext.Ajax.request({
        url: 'PHP function call',
        success: function(response) {
            myWin.open('http://www.yahoo.com');  // --> this opens a new window, not tab
        }
    });
}
Community
  • 1
  • 1
PFrank
  • 323
  • 2
  • 4
  • 8

3 Answers3

1

This is timing. If your request takes more then ~3s browser will think it's popup window. Take a look on my question couple weeks ago: window.open(url) different behavior - same code, different timing

Community
  • 1
  • 1
sha
  • 17,824
  • 5
  • 63
  • 98
  • Thanks for your reply. My PHP call takes <1sec to finish. Just to be sure, I replaced the original PHP code with a super light-weight one line and I still saw the same inconsistent behavior. – PFrank Apr 06 '12 at 23:37
  • Try to add alert('something'), right before you do win.open() – sha Apr 07 '12 at 00:41
0

I suspect that it might be a scope issue. Where the AJAX call is running in a separate 'window' from the rest of the scripting.

Have you tried something like:

function myFunction() {
    Ext.Ajax.request({
        url: 'PHP function call',
        success: function(response) {
            openWindows('http://www.yahoo.com');
        }
    });
}

function openWindows(url){
   window.open(url);
}
Justin Pearce
  • 4,994
  • 2
  • 24
  • 37
0

Have you tried something like:

function myFunction() {
    window.open('http://www.yahoo.com');  // --> this opens a new tab on my browser
    Ext.Ajax.request({
        url: 'PHP function call',
        success: function(response) {
            this.apply(openWindow);
        }
    });
}

function openWindow()
{
     window.open('http://www.yahoo.com');
}
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
byte_slave
  • 1,368
  • 1
  • 12
  • 24