Javascript: Select text on a page and search in google

There are a few demonstrations out there of how to invoke a search on the current text selection.

This is a stab at doing it in a non-intrusive way.

5 Responses to “Javascript: Select text on a page and search in google”

  1. Doc Says:

    That is a really great little code snippet. Probably one of the most useful I’ve used! I wrapped it up in a .js file and included it.

    One question I have is that on my site for some reason in Mozilla Browsers the little G is locked into the upper left hand corner and I can’t seem to unlock it.

  2. Lloyd Dalton Says:

    Thanks for creating the .js. The custom formatting looks nice too. The positioning issue has something to do with the loose.dtd in your DOCTYPE:

    < !DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”"http://www.w3.org/TR/html4/loose.dtd”>

    Switch the doctype to:

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

    and watch the problem disappear :)
    I have to plead ignorance about exactly why the doctype causes the absolute positioning to not work. But switching doctypes shouldn’t cost you anything–the page doesn’t validate anyway :)

  3. huphtur Says:

    firebird has this standard under the right mouse button

  4. Lloyd Dalton Says:

    Hey, you’re right!

    It took me a few minutes to figure out your comment. For anyone who’s still scratching their head–in Firebird, if you select some text and then right-click on the selection, one of the menu options is “Web search for ‘ABC’” where ABC is your selection.

    Dang, all that work for nothing :)

  5. Doc Says:

    LOL! You would tell me to change my DOCTYPE..

    I lust added the loose.dtd to get the darned thing to validate!

    Even if Firebird does have this option, IE doesn’t, not to mention the pure “cool factor!” :)
    Thanks again.

    Did you grab the .js??