Search code examples
javascripthtmlcsssliding-doors

Prevent blank links (having javascript:;) from openening in new tab/window on middle click...?


There is a common practice of using <a></a> tags to markup beautiful buttons, with onlick and onhover style change, etc. Which looks and behaves great, on most part.

Although there turned out to be a HUGE problem, which was not very obvious on start. The problem is that these beautiful "buttons" open new windows on middle click, either blank or with the same content as current one (depends on whether one uses # or javascript:; to disable href part).

Now I've got JavaScript RIA with buttons all over it, opening new windows on middle click... Lame...

At first I even couldn't understand why I get sometimes those blank pages in the browser.

Since it's pretty established practice to use links in such manner, maybe there is any established way to deal with described problem?


Solution

  • What I did in the end, was that I replaced all <a>...</a> tags with <span>...</span>s. The only problem with this is that IE doesn't support :active on spans, so I do not really get interactive buttons anymore in IE.