Safari and window.open – How to do it

Posted by filed under Browser Struggle.

There is still some traffic coming in from people who are searching for how to deal with the safari popup blocker. So I thought it might be nice to also tell what you can do about it – as most people want solutions, not backgrounds…

So, here you go:

It’s pretty simple, really. What to do? Well, call window.open() while the popup blocker still allows it, and store a reference to the window object. Then, later, do with it what you want. That is, changing the location in most cases.

Huh, that’s all? No magic? Nope, sorry. The popup blocker’s rules cannot be bent.

Say, you have a connection like this (I stay with the example code of the prior post):

dojo.connect(dojo.byId('b9'),'onclick',function(evt){
    dojo.publish('/opener/callOpen');
});

Then call window.open in your subscription:

dojo.subscribe('/opener/callOpen',function() {
    var winRef = window.open();
    dojo.xhrGet({
        url: window.location.href,
        load: dojo.hitch(opener,function(){
            this.open(winRef);
        })
    });
});

And let your open() know there might be a window object coming in:

opener = {
    open: function(windowReference) {
        var newWin = windowReference || window.open();
        // see if we get a window object
        console.log(newWin);
    }
};

In case your new window will be open and visible for some time until you can work with it, don’t forget to let the user know that the window will get some content in a few, e.g. point the new window’s url to some nice “please wait” page.

One Response to Safari and window.open – How to do it


  1. […] Update: If you are interested in how to make window.open work you might want to also read the follow-up: Safari and window.open – How to do it […]

[Comments are automatically closed after 30 days.]

Comment via Google+