I'm trying to create a bookmarklet that uses Google to search the current site. I want to be able to type the query directly in the location bar, rather than have it throw up an alert dialog prompting me for the query. What I've come up with so far seems to work most of the time, but fails when the query contains special characters such as ' or +:
Keyword: gss
Location: javascript:document.location='https://www.google.com/search?hl=en&q=%s+site:'+document.location.hostname;
It seems that SeaMonkey isn't doing URL character encoding on the query (%s). So when I visit http://www.example.com and type "gss c++", I get taken to
https://www.google.com/search?hl=en&q=c+++site:www.example.com
instead of
https://www.google.com/search?hl=en&q=c%2B%2B+site:www.example.com
and when I type "gss i'm a teapot" the bookmarklet doesn't work at all, presumably because the apostrophe in "i'm" closes the string and results in a JavaScript syntax error.
Is this a bug in SeaMonkey? It does do URL character encoding in non-JavaScript bookmarklets. For example,
Keyword: g
Location: https://www.google.com/search?hl=en&q=%s
works as expected for queries such as "c++" and "i'm a teapot".
Creating a Google site search bookmarklet
- Psychonaut
- Posts: 109
- Joined: April 7th, 2008, 3:56 am
- Location: Winnipeg
- Contact:
- Psychonaut
- Posts: 109
- Joined: April 7th, 2008, 3:56 am
- Location: Winnipeg
- Contact:
Re: Creating a Google site search bookmarklet
Hearing no responses, I presume that this is indeed a bug with how SeaMonkey handles %s keyword substitution. I've raised a bug on the issue tracker: Bug 1374356