Take the 2-minute tour ×

Within a setTimeout, I am setting the location of a newly opened window. To avoid the pop-up blocker, the window is opened with a temporary local URL, and then location is changed to the target URL. This works fine on all desktop browsers including Safari.

However, in Mobile Safari, the location of the new window is not updated until the user returns their focus to the originating window i.e. the temporary page is left sitting there.

This is what the relevant bit of the JavaScript/jQuery looks like:

var self = $(this);
if (self.is("a")) {
    var clickEventHandler = function(event) {
        if (self.attr("target")) {
            var newWindow = window.open('loading.htm',self.attr("target"));
            var externalURL=self.attr("href");
            setTimeout( function() { newWindow.location=externalURL; }, 100 );
    $(this).bind("click", eventHandler);
share|improve this question
Why do you need to do this within setTimeout? –  Michael Mior Dec 19 '12 at 16:36
I'd guess that mobile Safari defers setTiemout until focus is returned. What happens for you do document.body.innerHTML += new Date().toLocaleString() in a setTimeout? What time does it report when you return from a different window? –  apsillers Dec 19 '12 at 16:40
@Michael-Mior This approach is needed because I am tracking the event in Google Analtyics, and this will not work without introducting a short delay, see this SO thread –  mmorrey Dec 19 '12 at 17:09
@apsillers yes, exactly that. I tried your test, and it reports the time that I returned to the original window. I'll put a test page up publicly somewhere. –  mmorrey Dec 19 '12 at 17:47
Apparentely, this is a known problem with Mobile Safari –  mmorrey Jan 22 '13 at 12:47
show 1 more comment

Your Answer



Browse other questions tagged or ask your own question.