Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open new window after a click event not working in Safari, Chrome

I'm trying to open a new window like so:

$('#wrapper').click(function() {
    window.setTimeout(function() {
        //alert('hi');
        window.open("http://example.com", "ExternalLinks", "resizable=yes, scrollbars=yes, status=yes");
    }, 1000);
});

This works in Firefox, but not in Chrome or Safari (so far, I've just tested on a Mac). The alert() works in all browsers, so there seems to be something preventing the window.open from executing in Safari/Chrome. Furthermore, if I remove the setTimeout and just call the window.open then it does work in all 3 browsers. It's almost like if the window.open is nested too far away from the click event, then it doesn't work in Safari/Chrome.

So you know, I have an all-Flash website and I'm trying to get external links to open in a new window, so I'm reading the hash tag in the URL (ex. htp://example.com/#/facebook/) and if it matches certain items, then I'm calling window.open to open a specific URL. I don't have access to the Flash source, or I would handle this there.

Any ideas?

like image 238
matthewpavkov Avatar asked Jan 11 '11 23:01

matthewpavkov


People also ask

How do I open a new window in Safari?

You've not told us what Safari version you have. However in Safari 6.0.5, if you CLICK and HOLD the Dock's Safari icon, one option that pops up is "New Window": You could also use command-n or click on File new window. That's it.

How do I open a new window in Google Chrome?

Just add chrome to you task bar. Right click and choose new window. Easy cheesy... And, Google is not a POS. We all need to stop drinking before we post. Our automated system analyzes replies to choose the one that's most likely to answer the question. If it seems to be helpful, we may eventually mark it as a Recommended Answer. Helpful?

What does it mean when it says “open windows only” on Chrome?

It makes Chrome only open windows instead of opening tabs. Our automated system analyzes replies to choose the one that's most likely to answer the question. If it seems to be helpful, we may eventually mark it as a Recommended Answer.

Are there any apps that open default browser windows from embedded links?

Unfortunately, there are other apps that open default browser windows from embedded links.


1 Answers

Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.

like image 121
Ben Lee Avatar answered Sep 27 '22 22:09

Ben Lee