Encode special characters to pass in url and read by javascript
This question already has an answer here:
例如,您可以尝试encodeUri内置函数
encodeURI('coño funcionó!')
Previous answer is correct. JavaScript has built in functions for fulfilling this kind of tasks.
You can try to investigate these functions in w3schools.com. Here are the links with basic information and live "Try it out" feature: