How To Quickly Search Your Favourite Website For Selected Text With A Bookmarklet

If you find something interesting on the net and want to see if it's been mentioned on one of your favourite sites, Lifehacker reader The_Doc has created a bookmarklet to search Google for the currently selected text with a site: operator.

His explanation:

If you highlight text on a webpage (not in a textbox) and click on the bookmarklet, a new tab/window will open and perform a site:lifehacker search on google for that highlighted text. If you click on the bookmarklet with no text highlighted, a prompt appears. Type in your desired search, hit 'OK', and a new tab/window opens, searching for that text. If you hit 'OK' with the prompt blank, it opens a new tab/window and performs a blank search (which lists all articles)

This bookmarklet is better than a keyword search for searching highlighted text. Instead of highlighting, Ctrl+C, Ctrl+T, "lh " (or whatever), Ctrl+V, you simply highlight and hit the bookmarklet. Plus it also can act as a keyword search replacment for non-highlighted purposes.

For bonus points, in firefox use the Favicon Picker plugin to attach the lifehacker favicon to the bookmarklet and leave the name blank. This gives you a lifehacker logo'd button.

Just drag this link to your bookmarks bar to add it. Alternatively you can create a new bookmark and copy this code as its location:

javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search%20Lifehacker.com.au%20[leave%20selection%20and%20box%20blank%20to%20list%20all%20pages] %20...").replace(/s+/g,"%252B");if(q!=null)window.open('http://www.google.com/search?q=%27+%27site:lifehacker.com+%27+q.replace(/s+/g,%27+%27));void(0);

This particular bookmark is useful if you tend to use one site as your go-to resource. For example, if you find a cool web service or piece of software and want to see if Lifehacker has ever done a how-to for it, you can use this bookmarklet to find out. You can, of course, replace the lifehacker.com.au parts of the above code with a different domain to make it work with any other site.

You can also make the search process even faster, for you keyboard junkies, by assigning that bookmarklet a keyboard shortcut using previously mentioned Firefox extensionSiteLauncher, or OS X's built in Keyboard Shortcuts preference pane if you're a Mac user.

There are some other really useful bookmarklets at iMilly.com too, such as ones that allow you to search whatever site you're on for other iterations the selected text, as well as one that just searches Google for the selected text. Be sure to check them out, and let us know your quick search techniques in the comments.


Comments

    Yes, I know this articles old, but perhaps someone with the know-how will read/get my comment and be able to help. I don't really understand coding but is it possible to use the above code to search more then one favorite site, perhaps two or three? If so, could someone display such a code for me please.

    Thanks,

Join the discussion!

Trending Stories Right Now