PDA

View Full Version : Charactor Replacing in HTML (Cross-Browser Code) How?



alMubarmij
01-10-2007, 06:11 PM
Hi ..

I have an idea to replace some charactor by another one in web pages by JavaScript.

I want now to replace the each digite number (1, 2, 3 ...) by Unicode codes like:
&#1500 ;
&#1220 ;
&#1200 ;
&#1202 ;
&#1203 ;
..etc. if I used the previous code it will replace the Unicode code numbers.

I can do this simply in PHP language functions like str_replace() but it's a server-side language, I want a cleint-side method by JavaScript.
Also I need a cross-browser code using DOM.
Can any JavaScript professional help me ?

Kenny
01-10-2007, 06:32 PM
like this?


<HTML>
<HEAD><TITLE> </TITLE>
<BODY onload="abc()">

1 2 3 4 5 6 7 8 9 0

<SCRIPT type="text/javascript">
function abc(){
var rep=new Array('&#1500','&#1220','&#1200','&#1202','&#1203');
var str=document.getElementsByTagName('body')[0];
for(i=0;i<rep.length;i++){
str=str.replace(/i/g, rep[i])
}
document.write(str)
</SCRIPT>

</BODY></HTML>

alMubarmij
01-11-2007, 10:26 AM
I tried it on IE and Firefox, but it's not work.

I want something doing like this:


0 = &#1200 ;
1 = &#1500 ;
2 = &#1220 ;
3 = &#1201 ;
4 = &#1202 ;
5 = &#1203 ;
6 = &#1204 ;
7 = &#1205 ;
8 = &#1206 ;
9 = &#1207 ;

Note:
I put a space before ";" because the forum treat with the code as a HTML, and it will replace it.

Kenny
01-11-2007, 12:08 PM
This might be on track but all I get are squares in return

<HTML>
<HEAD><TITLE> </TITLE>
<BODY onload="abc()">
<hr>
1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 0 j
<hr>
<SCRIPT type="text/javascript">
function abc(){
var rep=new Array('&#1200','&#1500','&#1220','&#1201','&#1202','&#1203','&#1204','&#1205','&#1206','&#1207');
var str=document.getElementsByTagName('body')[0].innerHTML;
for(i=0;i<rep.length;i++){
var rx=new RegExp(i,"g");
str=str.replace(rx, rep[i])
}
document.write(str)
}
</SCRIPT>

</BODY></HTML>