I’m writing a Greasemonkey script. I need to compare two strings, where one of these is equal to document.location.href.
If document.location.href is equal to "http://lema.rae.es/drae/?val=ñáñara" then I need to do something extra, but I can’t determine if the two strings are equal, because document.location.href is converted to another character set. This is an example:
var currentLocation = document.location.href.toString();
var targetLocation = 'http://lema.rae.es/drae/?val=ñáñara';
alert(currentLocation + '\n' + targetLocation);
/* OUTPUT:
http://lema.rae.es/drae/?val=%C3%B1%C3%A1%C3%B1ara
http://lema.rae.es/drae/?val=ñáñara
*/
How can I convert two strings to the same character set?
Just use:
Should be enough.
See: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/decodeURI