function resolveIDNA(url) {
var a = document.createElement("a");
a.href = url;
return a.href;
}
Test your browser, or try your own IDN domains!It doesn't seem to work in all browsers yet, though; of those I've tested, Firefox 3 and Safari 3 both support it, whereas Opera 10.4.11 and Google Chrome 1.0.154.65 do not.
Update: Both as my google memory didn't find this when I sought it out (decoding a non-ASCII, non-IDNA-encoded hostname to its punycode/IDNA-encoded ASCII counterpart), and for having found a use for this in the wild, here is the altered function that just takes a unicode hostname and turns it into its punycode/IDNA form:
function IDNAtoASCII(hostname) {
var a = document.createElement("a");
a.href = "http://" + hostname + "/";
return a.hostname;
}
Works in Google Chrome 1.0.154.59
ReplyDeleteHey, that's a great example of benefits of code reuse!
ReplyDelete