WordPress Search Bookmarklet

Alan Levine aka CogDog barked this May 4th, 2005 9:16 am

As part of the blog transition I took a spin at creating a new tool that would create a WordPress search bookmarklet, more or less a quick re-do of the one I originally created for MovableType.

It is even easier to construct for WordPress, as all you need to know is the base URL for the WP blog- the WordPress search URL is very simple, merely the URL plus a value to pass for the key word search:

http://www....WP-blog-url/index.php?s=blog

making it really easy to create permanent bookmarks for blog searches, e.g., my spam roach collection:

http://cogdogblog.com/index.php?s=spam+roach.

Hmmm, this is a sneaky way to make new pseudo categories.

Anyhow, another cheap WP hack is the new Make a WordPress Search Bookmarklet- it allows you to create a browser bar tool that can either do a search of a particular WP blog using any text highlighted in a page, or it will pop up an input box for entering the search terms.

This way you can search any WordPress Blog w/o having to go to the blog itself and use the search form.

This would have been easier, except I found out testing that recent versions of Safari and Firefox treat the JavaScript getSelection() function differently, whereas before it was always a string, now it is an object, but apparently methods of the result behave differently. The fix, with help from Joe Maller’s blog, is to contcatenate the results with an empty string, thus you end of with a string to test with again.

So any old bookamrket that relied on:

t=getSelection(); if (!t) ...

is broken as on some browsers the results when there is no selection range from “undefined” to “” to ???. The easy fix was to adjust the code to force conversion to a string:

t=getSelection()+''; if (!t) ...
so the if() statement is forced to be testing a tring.

Technorati Tags:

This entry was posted 3 years, 6 months ago and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License
and may be patrolled by a friendly small dog (with a wagging tail)
This means you are free to use any original content published here (begs the question why)
as long as you provide linktribution.

.
Clicky Web Analytics