Bookmarklets for search

As seen in the Bookmarklet article, this feature of HTML and JavaScript that was from the outset supported by browsers, can provide extended features.

We'll see how to add advanced search functions to the browser, and you have just to add the bookmarklet as a link into the sidebar of bookmarks.

Simple search

Opens a dialog box to search on Google. The results are displayed in a new page.

javascript:(function()
{
  var p=prompt('Search on Google:','');
  if(p)
  {
     document.location.href='https://www.google.com/search?query='+escape(p)
  }
})();

Search on the current website

Perform a search limited to the website of the page displayed by the browser.

javascript:(function() 
{   
   var p=prompt(Search on Google:','');
   if(p)
   {
      document.location.href='https://www.google.com/search?q=site:'+document.location.href.split('/')[2]+'+'+escape(p)
   } 
})();

Similar pages

Search page similar to the current page, a service provided by Google.

javascript:(function()
{
     document.location.href='https://www.google.com/search?q=related:'+escape(document.location.href);
})();

Searching royalty-free image

To find public domain image with Google Images.

javascript:(
  function()
  {
    p=prompt(Images%20Search:','');
    if(p)
    {
     document.location.href='http://images.google.com/images?query='+escape(p)+'&as_rights=cc_publicdomain';
    };
  }
)();

Adding a bookmarklet to bookmarks

To retrieve the code of the bookmarklets, load the page with an HTML editor, Open Office for example, click on the link and take the contents of the href attribute.

Then go to the bookmark panel of the browser, choose a folder and click the right mouse button to open the menu. Click on "New bookmark", insert the code in the URL field and choose a name for the bookmarklet.

See also

© 2008-2012 Xul.fr