google search site bookmarklet

Discussion in 'Javascript' started by gwtc, Jul 2, 2006.

  1. gwtc

    gwtc Guest

    Here is a google search site bookmarklet. This lets you search a
    certain website using google. What I want is the same thing, but to
    search a certain geocities site. When you use the current
    bookmarklet, the search takes you to site:www.geocities.com instead of
    the specific site you want to search. Can someone modify this for me,
    to search specific geocities sites?

    Thanks for your help and btw I'm using Mozilla Suite and Firefox.

    The bookmarklet is:

    javascript:(function(){var
    h,q;h=location.hostname;q=(window.getSelection ? window.getSelection()
    : document.getSelection ? document.getSelection() :
    document.selection.createRange().text);q=prompt('Search \''+h+'\'
    using Google:',q);if(q!=null){if(h){q='site:'+h+'
    '+q;}location='http://www.google.com/search?q='+encodeURIComponent(q);}})();

    --
    Murphy's Laws of Computing: The number one cause of computer problems
    is computer solutions.
     
    gwtc, Jul 2, 2006
    #1
    1. Advertising

  2. gwtc

    Ivo Guest

    "gwtc" schreef
    > Here is a google search site bookmarklet. This lets you search a certain
    > website using google. What I want is the same thing, but to search a
    > certain geocities site. When you use the current bookmarklet, the search
    > takes you to site:www.geocities.com instead of the specific site you want
    > to search. Can someone modify this for me, to search specific geocities
    > sites?
    >
    > Thanks for your help and btw I'm using Mozilla Suite and Firefox.
    >
    > The bookmarklet is:
    >
    > javascript:(function(){var h,q;h=location.hostname;q=(window.getSelection
    > ? window.getSelection() : document.getSelection ? document.getSelection()
    > : document.selection.createRange().text);q=prompt('Search \''+h+'\' using
    > Google:',q);if(q!=null){if(h){q='site:'+h+'
    > '+q;}location='http://www.google.com/search?q='+encodeURIComponent(q);}})();


    I gather you want to add the pathname up to the first '/' slash after the
    hostname. In code (mind the wrap):

    h==location.hostname + location.pathname.substring( 0,
    location.pathname.substring(1).indexOf( '/' )+1 )

    That would give you strings like 'www.geocities.com/swaisman' or
    'www.geocities.co.jp/goofy_trip'.

    hth
    ivo
     
    Ivo, Jul 2, 2006
    #2
    1. Advertising

  3. gwtc

    gwtc Guest

    Ivo wrote:

    > "gwtc" schreef
    >
    >>Here is a google search site bookmarklet. This lets you search a certain
    >>website using google. What I want is the same thing, but to search a
    >>certain geocities site. When you use the current bookmarklet, the search
    >>takes you to site:www.geocities.com instead of the specific site you want
    >>to search. Can someone modify this for me, to search specific geocities
    >>sites?
    >>
    >>Thanks for your help and btw I'm using Mozilla Suite and Firefox.
    >>
    >>The bookmarklet is:
    >>
    >>javascript:(function(){var h,q;h=location.hostname;q=(window.getSelection
    >>? window.getSelection() : document.getSelection ? document.getSelection()
    >>: document.selection.createRange().text);q=prompt('Search \''+h+'\' using
    >>Google:',q);if(q!=null){if(h){q='site:'+h+'
    >>'+q;}location='http://www.google.com/search?q='+encodeURIComponent(q);}})();

    >
    >
    > I gather you want to add the pathname up to the first '/' slash after the
    > hostname. In code (mind the wrap):
    >
    > h==location.hostname + location.pathname.substring( 0,
    > location.pathname.substring(1).indexOf( '/' )+1 )
    >
    > That would give you strings like 'www.geocities.com/swaisman' or
    > 'www.geocities.co.jp/goofy_trip'.
    >
    > hth
    > ivo
    >
    >

    Thanks ivo, but I'm not javascripted minded. Where do I add those lines?

    --
    Murphy's Laws of Computing: The number one cause of computer problems
    is computer solutions.
     
    gwtc, Jul 2, 2006
    #3
  4. gwtc

    Ivo Guest

    "gwtc" schreef
    > Ivo wrote:
    >> I gather you want to add the pathname up to the first '/' slash after the
    >> hostname. In code (mind the wrap):
    >>
    >> h==location.hostname + location.pathname.substring( 0,
    >> location.pathname.substring(1).indexOf( '/' )+1 )
    >>
    >> That would give you strings like 'www.geocities.com/swaisman' or
    >> 'www.geocities.co.jp/goofy_trip'.
    >>

    > Thanks ivo, but I'm not javascripted minded. Where do I add those lines?


    Find in your code the bit that sais:
    h=location.hostname
    and add immediately after that:
    + location.pathname.substring( 0,
    location.pathname.substring(1).indexOf( '/' )+1 )

    So you get:
    javascript:(function(){var h,q;h=location.hostname +
    location.pathname.substring( 0, location.pathname.substring(1).indexOf(
    '/' )+1 );q=(window.getSelection ? window.getSelection() :
    document.getSelection ? document.getSelection() :
    document.selection.createRange().text);q=prompt('Search \''+h+'\' using
    Google:',q);if(q!=null){if(h){q='site:'+h+'
    '+q;}location='http://www.google.com/search?q='+encodeURIComponent(q);}})();

    Untested, but should work. I 'm not geocities minded.
    ivo
     
    Ivo, Jul 4, 2006
    #4
  5. gwtc

    gwtc Guest

    Ivo wrote:

    > "gwtc" schreef
    >
    >>Ivo wrote:
    >>
    >>>I gather you want to add the pathname up to the first '/' slash after the
    >>>hostname. In code (mind the wrap):
    >>>
    >>>h==location.hostname + location.pathname.substring( 0,
    >>>location.pathname.substring(1).indexOf( '/' )+1 )
    >>>
    >>>That would give you strings like 'www.geocities.com/swaisman' or
    >>>'www.geocities.co.jp/goofy_trip'.
    >>>

    >>
    >>Thanks ivo, but I'm not javascripted minded. Where do I add those lines?

    >
    >
    > Find in your code the bit that sais:
    > h=location.hostname
    > and add immediately after that:
    > + location.pathname.substring( 0,
    > location.pathname.substring(1).indexOf( '/' )+1 )
    >
    > So you get:
    > javascript:(function(){var h,q;h=location.hostname +
    > location.pathname.substring( 0, location.pathname.substring(1).indexOf(
    > '/' )+1 );q=(window.getSelection ? window.getSelection() :
    > document.getSelection ? document.getSelection() :
    > document.selection.createRange().text);q=prompt('Search \''+h+'\' using
    > Google:',q);if(q!=null){if(h){q='site:'+h+'
    > '+q;}location='http://www.google.com/search?q='+encodeURIComponent(q);}})();
    >
    > Untested, but should work. I 'm not geocities minded.
    > ivo
    >
    >

    bingo. Thanks ivo. It works great.

    --
    Murphy's Laws of Computing: A complex system that does not work is
    invariably found to have evolved from a simpler system that worked
    just fine.
     
    gwtc, Jul 4, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=

    Google search result like site search!! How?

    =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    684
    Lucas Tam
    May 6, 2005
  2. Bruce W...1

    Search your site with Google?

    Bruce W...1, Oct 31, 2003, in forum: HTML
    Replies:
    7
    Views:
    441
    Barry Pearson
    Nov 8, 2003
  3. Replies:
    3
    Views:
    315
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 26, 2007
  4. Chris K.
    Replies:
    3
    Views:
    742
    Chris K.
    Jun 8, 2008
  5. Replies:
    2
    Views:
    346
Loading...

Share This Page