extjs 4.0 inconsistent window.open() behavior when

2019-06-14 12:11发布

问题:

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
        }
    });
}

回答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



回答2:

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);
}


回答3:

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');
}