To urlencode string in JavaScript (as PHP’s urlencode() function does), use the escape() function. For example: var sSearchKeyword = ‘!@#$%^&*abcd1234′; location.href = ‘http://example.com/search.php?keyword=’ + escape(sSearchKeyword); Note: escape() doesn’t encode “+” and “/” chars. The solution can be found using replace these characters by replace() method: var sSearchKeyword = ‘!@#$%^&*abcd1234+/’; sSearchKeyword = escape(sSearchKeyword); sSearchKeyword = sSearchKeyword.replace(’+', [...]
If you enjoy our post, feel free to subscribes to our rss feeds
