Jump to Real's How-to Main page

Encode a URL

escape() encodes most of the stuff you need to encode. It misses single and double quotes, so you should replace those manually.
function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }

Encode the following URL : www.google.com/search?q=Real's HowTo


If you find this article useful, consider making a small donation
to show your supportfor this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]