Escaping special characters in JavaScript
JavaScript has some inbuilt functions for escaping special characters. The most common one and the one that is available in all versions from 1.0 upwards is escape().
Here are some related links to pages explaining special character replacement in greater details: