0

私は Greasemonkey スクリプトを書いています。2 つの文字列を比較する必要があり、そのうちの 1 つが に等しくなりdocument.location.hrefます。

document.location.hrefが等しい場合"http://lema.rae.es/drae/?val=ñáñara"、何か特別なことをする必要がありますが、document.location.href別の文字セットに変換されるため、2 つの文字列が等しいかどうかを判断できません。これは例です:

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
*/

2 つの文字列を同じ文字セットに変換するにはどうすればよいですか?

4

2 に答える 2

3

使用するだけです:

var url = decodeURI(window.location.href);

十分なはずです。

参照: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/decodeURI

于 2013-02-19T16:13:15.383 に答える
1

またはその逆:encodeURI("http://lema.rae.es/drae/?val=ñáñara")

于 2013-02-19T16:14:23.340 に答える