wubaie Posted March 9, 2015 Share Posted March 9, 2015 In JavaScript String charCodeAt() Method Chapter , I use Chinese word for test string, but I can not get the correct unicode result. Link to comment Share on other sites More sharing options...
davej Posted March 9, 2015 Share Posted March 9, 2015 There are various blog discussions of Javascript unicode problems, such as... https://mathiasbynens.be/notes/javascript-unicode Link to comment Share on other sites More sharing options...
wubaie Posted March 9, 2015 Author Share Posted March 9, 2015 I mean the same Javascript code in w3school [try it yourself] and in a real html file. But the return unicode result is not same. I think w3school have not the correct simulation coding in JavaScript String charCodeAt() Method Chapter. Link to comment Share on other sites More sharing options...
davej Posted March 9, 2015 Share Posted March 9, 2015 This code? http://www.w3schools.com/js/tryit.asp?filename=tryjs_string_charcodeat I believe the article I mentioned above says that Javascript itself does not handle all unicode correctly. <!DOCTYPE html><html><head><meta charset="utf-8"/><title>utf-8</title><style></style><script>window.onerror = function(a, b, c, d){alert('Javascript Error:n'+a+'nURL: '+b+'nLine: '+c+' Column: '+d);return true;}</script><script>'use strict';window.onload = init;function init() {document.getElementById('btn1').onclick = put;}function put(){var str = "Iñtërnâtiônàlizætiøn☃.";var str2 = "";for(var i=0,len=str.length ; i<len ; i++){ str2 += str.charAt(i) + "=" + str.charCodeAt(i) + " ";}document.getElementById("out").innerHTML = str2;}</script></head><body><p>Iñtërnâtiônàlizætiøn☃.</p><input type="button" id="btn1" value="Enter"><div id="out"></div></body> </html> Link to comment Share on other sites More sharing options...
Ingolme Posted March 10, 2015 Share Posted March 10, 2015 W3Schools doesn't simulate Javascript. Whatever W3Schools does is real Javascript and it's bound by the same limitations Javascript is. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now