bookmarklet for a random link in a new tab
February 27, 2011 5:06 AM   Subscribe

In Firefox, how can I get my bookmarklet to open a link in a new tab?

I'm looking for a bookmarklet that will open a random link on the current page, in a new tab. I found a couple of random link openers:

javascript:void(window.open(document.links[Math.floor(Math.random()*document.links.length)].href,'_self'));

javascript:void(location.href=document.links[Math.floor((document.links.length)*Math.random())])

but both of them just open the link in the same tab I'm in. Is there a way to modify either of these to open new tabs, or, alternatively, some other one-click way to open a randomly selected link?
posted by maqsarian to Computers & Internet (6 answers total) 1 user marked this as a favorite
 
Best answer: take the '_self' bit off the first one, or change it to a different name. _self refers to the current window anything else (except '_parent' or '_top' which also do special things), or nothing, will mean it opens in a new window.
posted by gregjones at 5:29 AM on February 27, 2011


Best answer: you want '_blank' instead of '_self' in the first one.
posted by jedrek at 6:21 AM on February 27, 2011


In the second one, change "void(location.href=blah)" to "void(window.open(blah,'_blank'))".
posted by mbrubeck at 7:54 AM on February 27, 2011


Response by poster: Sweet. Thanks!
posted by maqsarian at 8:52 AM on February 27, 2011


Middle-clicking on a three button mouse opens bookmarks and normal links in a new tab. On my 2-button laptop, chording the buttons (pushing and releasing both buttons together) is interpreted as a middle button press and does the same thing.
posted by NortonDC at 11:19 AM on February 27, 2011


Response by poster: Yes. Middle-clicking on a bookmarklet, though, just opens a new tab to javascript:whatever.
posted by maqsarian at 11:35 AM on February 27, 2011


« Older How to overcome feeling lost, aimless, confused...   |   Where can I stream the Academy Awards tonight? Newer »
This thread is closed to new comments.