User:Hao2lian/Keyword search character encoding

From MozillaZine Knowledge Base

If you have a Google keyword, and you use it to search for something such as "C++," it won't work because the plus sign is a special character in URLs. So Google will only search for "C".

The hack

javascript:document.location = "" + encodeURIComponent('%s');

Disadvantages of said hack

  • The JavaScript URL will flash briefly before changing.
  • You need to backslash your single quotes now, or else the JavaScript screws up.
  • If the JavaScript fails, there will be no error message. Just one angry JavaScript string in the Location Bar.