Code for replacing special characters in an URL while passing the URL to an XML file.

URL may contain special characters like &, coma, etc but some special characters will not support on XML.

the below code can be used for replacing special characters in the URL.

var value = "url" // type url here
var value1;  // varibale to store the new url

    value1 = value.replace(/&/g, "&")
    value1 = value1.replace(/</g, "&lt;")
    value1 = value1.replace(/>/g, "&gt;")
    value1 = value1.replace(/"/g, "&quot;")
    value1 = value1.replace(/'/g, "'");

return value1

Leave a comment

Your email address will not be published. Required fields are marked *