Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript html unicode 1

Status
Not open for further replies.

shekinskiy

Programmer
Nov 14, 2005
11
TR
hi

i have a problem with html unicode character.
it runs correctly in html code, rise problem while it is between script tag and i need that the message should be between script tag.

second link, first statement and third statement in function shows alphabetic characters (not unicode), but second statement in function shows unicode characters as it is in code.

Code:
<html>
<head>
<title>Alert</title>
</head>
<script>
function fnctn(aaa) {
	alert(aaa); //no problem, show characters
	alert("&#305;&#287;&#252;&#351;&#246;&#231;&#304;&#286;&#220;&#350;&#214;&#199;"); //problem, shows unicode character
	alert("\u0131\u011F\u00FC\u015F\u00F6\u00E7\u0130\u011E\u00DC\u015E\u00D6\u00C7"); //no problem, show characters
}
</script>
<body>
<a href="#" onclick='javascript:fnctn("&#305;&#287;&#252;&#351;&#246;&#231;&#304;&#286;&#220;&#350;&#214;&#199;");'>Test</a>
<br/>
<a href="#" onclick='javascript:alert("&#305;&#287;&#252;&#351;&#246;&#231;&#304;&#286;&#220;&#350;&#214;&#199;");'>Test</a>
</body>
</html>
 
There's no problem - the second alert is showing exactly what you're asking it to. If you want to convert it to HTML characters from their character entities, you need to run it through some sort of conversion function.

A lot of conversion functions have lookup tables - but I think getting the browser to do the work is a far better idea. This works for me:

Code:
<html>
<head>
</head>
	<script type="text/javascript">
		var theStr = '&#305;&#287;&#252;&#351;&#246;&#231;&#304;&#286;&#220;&#350;&#214;&#199;';
		function convertHtmlEntitiesToCharacters() {
			var newDiv = document.createElement(newDiv);
			newDiv.innerHTML = theStr;
			alert('Entities:\n' + theStr + '\n\nCharacters:\n' + newDiv.innerHTML);
		}
	</script>
<body onload="convertHtmlEntitiesToCharacters();">
</body>
</html>

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
In fact, I've just added that as an FAQ - it's the sort of thing other people would probably find handy:

Converting HTML character entities to characters (faq216-6361)

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top