6

Is it possible to style the hyperlink tag in CSS in such a way that when a link is clicked it opens it in a new tab or window? I know the solution in HTML and JavaScript/jQuery, yet is it possible to specify this attribute using a stylesheet? Also note that this question is important because it could possibly save me many keystrokes and code clutter. Thanks for your mind and time. =)

HTML:

target="_blank"

jQuery/JavaScript:

window.open($(this).attr("href"), '_blank', 'modal=yes');

Css:

.class a {
 ???
}
Trey Shaffer
  • 129
  • 1
  • 1
  • 8
  • 2
    no thats not possible – jmore009 Jan 13 '15 at 05:10
  • If by "save [you] many keystrokes", you mean that you have a lot of links that you'd have to put `target="_blank"` on, then use code editing tools with find/replace functionality. – ajp15243 Jan 13 '15 at 05:14
  • Well, that would clutter my code quiet a bit more than it already is. It's ok if I have to, but it would be best if the HTML code could be minimalist as possible. – Trey Shaffer Jan 13 '15 at 05:17
  • So use `$('a.x').attr('target', '_blank')` for all links with "x" class, or remove ".x" for all links. If you don't want to use jQuery, try `var s = document.getElementsByClassName('x'); for (var i = 0; i < s.length; i++) s[i].setAttribute('target', '_blank');` for pure JS. I'm affraid it can't be done simplier, if only SOME links are to be affected. – Harry Jan 13 '15 at 06:25

1 Answers1

10

Seems it's not supported by current browsers, refer to http://www.w3schools.com/cssref/css3_pr_target-new.asp

imnancysun
  • 612
  • 8
  • 14