Results 1 to 4 of 4

Thread: Charactor Replacing in HTML (Cross-Browser Code) How?

  1. #1
    Join Date
    Apr 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Charactor Replacing in HTML (Cross-Browser Code) How?

    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:
    Code:
    &#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 ?

  2. #2
    Join Date
    Dec 2006
    Posts
    47
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default

    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>

  3. #3
    Join Date
    Apr 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried it on IE and Firefox, but it's not work.

    I want something doing like this:
    Code:
    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.
    Last edited by alMubarmij; 01-11-2007 at 10:33 AM.

  4. #4
    Join Date
    Dec 2006
    Posts
    47
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default

    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>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •