Wonko the Sane

You can't possibly be a scientist if you mind people thinking you're a fool

0 notes

Target _blank

Often lately I’ve been coming across pages with links which I want to open in new windows. Rather than wearing out my ⌘ key, I decided to make a bookmarklet to make all links target="_blank".

javascript:var s=document.createElement('script');s.setAttribute('src','http://jquery.com/src/jquery-latest.js');document.getElementsByTagName('body')[0].appendChild(s);setTimeout(function(){$("a").attr("target","_blank");},200);

Yes, it uses JQuery, because that was easier than finding out to select all a elements in vanilla Javascript. I also intended it for my own use, so I didn’t put much effort into finding what was most efficient.

Filed under javascript bookmarklet blank