function urlencode(str) { str = (str + '') .toString(); return encodeURIComponent(str) .replace(/!/g, '%21') .replace(/'/g, '%27') .replace(/\(/g, '%28') . replace(/\)/g, '%29') .replace(/\*/g, '%2A') .replace(/%20/g, '+'); } function urldecode(str) { return decodeURIComponent((str + '') .replace(/%(?![\da-f]{2})/gi, function() { return '%25'; }) .replace(/\+/g, '%20')); }