View Full Version : Looping and so on ...

04-21-2008, 11:51 PM
Hi all,

I have a problems with some national characters.. I'm using proper charset I think
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" /> and all characters work properly like , ć, etc. I have a small problem when I'm taking rss from another website .. in this case national characters appear like ? ... my question is should I write javascript (I don't know how to write it I'm still newbie with javascripts) which will loop trough body and replace all national characters if any with proper html symbol like
ć is same as &# 263;or another better solution is out there.

Thank you for your answers

04-22-2008, 12:59 AM
function strCode(str){
for(var a = 0; a < str.length; a++){
var tmp = str.substr(a, 1);
var output = "";
case "your_char_for_replacement":
output += "your_converted_char";
//more cases like the one above as needbe
output += tmp;
return output;
document.getElementById("your_container").innerHTML = strCode(document.getElementById("your_container").innerHTML);

not 100&#37; certain on this, but instead of a switch you may be able to do output += "&#"+tmp.charCodeAt(0)+";";

04-22-2008, 01:28 AM
thank you I think this will be very useful if not now will be later because I'm always encountering these kind of problems... just one more question ... since I don't have one big container which contains all parts of website I have header, body and footer all separated .. can I apply this to whole body ... sth. like
<body onload="strCode(this);"> sorry because this probably doesn't make sense but I'm trying to be accurate as I can thank you again for your time

04-22-2008, 01:32 AM
i suppose you could do that, but the this keyword doesn't make sense in that context as the parameter would be the id of the element to be passed, so you would have to assign an id to the body tag and pass the id you set

<body id="myBody" onload="strCode('myBody');">