Google Chrome is a bit weird nowadays in that v25 no longer respects a 302 redirect header and happily re-posts form data on page refresh, whereas v24 and all the other browsers play nicely. I'm not sure if this is just a temporary browser bug, so let me describe the mystery I'm trying to solve.
As far as I know you cannot open a tab using HTML or JavaScript, but a new window without explicitly set dimensions is going to open as a tab by default.
First I've tried this:
<a href="URL" onclick="window.open(this.href);return false">
<img src="NICE IMAGE" alt="foo">
</a>
This was working everywhere, except in Chrome where it was shot down as an unauthorized popup window. Interestingly, sometimes when I kept clicking on it, Chrome has changed its mind and let the link open anyway (as tab). This was not always the case though, sometimes the link remained dead.
After a couple of hours of experimenting (and having changed from onclick
to a simple target="_blank"
) I have discovered that the reason the link was killed is that the click event started from the <img>
tag within the <a>
. When I replaced the <img>
with a <span>
that contained some text and clicked on the <span>
, the link could not open (Chrome has identified it as an unwanted popup), but when I clicked on the <a>
tag itself (that had a fixed size or a padding), then it was accepted, and a new tab was born.
Finally I just included the images as CSS background and the <a>
tags remained empty. Everything seems to be working now in every browser with this markup:
<a href="URL" target="_blank" style="background:url('NICE_IMAGE'); height:XXX; width:XXX" title="Description"></a>
What could be the reason behind the Google Chrome’s logic that when a link contains a tag, then it is forbidden from being opened as a new tab, but when it is empty, then it can go ahead?