top | item 1621892

News.YC: open links in new tab

9 points| modulow | 15 years ago | reply

I know this is no great feat, but just wanted to post my bookmarklet, that I use to turn all the links on news.yc into `target="_blank"` links:

<a href="javascript:function%20getScript(url,%20success)%20{var%20d%20=%20document,script%20=%20d.createElement(%27script%27),head%20=%20d.getElementsByTagName(%27head%27)[0],done%20=%20false;script.src%20=%20url;script.onload%20=%20script.onreadystatechange%20=%20function(){if(%20!done%20&&%20(!this.readyState%20||%20this.readyState%20==%20%27loaded%27%20||%20this.readyState%20==%20%27complete%27)%20)%20{done%20=%20true;success();script.onload%20=%20script.onreadystatechange%20=%20null;head.removeChild(script);}};head.appendChild(script);}getScript(%22http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js%22,%20function()%20{if(%20typeof%20jQuery%20==%20%27undefined%27%20)%20{alert(%22jQuery%20could%20not%20be%20loaded%22);}$(%22td.title%20a%22).attr(%22target%22,%20%22_blank%22);});">YC - Open in new Tab</a>

6 comments

order
[+] mrduncan|15 years ago|reply
Alternatively, nearly all browsers support middle clicking on links to open them in a new window.
[+] Timothee|15 years ago|reply
Or, for laptops mostly, a combination of Ctrl, Shift, Alt + click will usually do the trick. (with the added benefit of choosing if you want to open it in the background or open it and see it right away, also true with middle-click)
[+] swedegeek|15 years ago|reply
On my netbook, I have a multi-touch trackpad, so a 2-finger tap does the trick as well. Even with the "target=_blank" I'd probably still do a middle-click/2-finger tap to have the new tab open in the background. That way, I can quickly scan HN (or reddit or whatever else) and open up all the items I'm interested in and then read through them rapid fire.

Good exercise, though!