Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: src escape:

  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts

    src escape:

    Something simple I put together to adapt src-code for a string variable.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
    <title>srcEscape</title>
    <script type="text/JavaScript">
    function srcEscape(){
    var inp, txt, Tabs = "", Spaces = "", TbSp, v, c, s, ss = "", vName;
    inp = document.getElementsByTagName("input");
    txt = document.getElementsByTagName("textarea");
    while (Tabs.length < Math.abs(inp[0].value)){Tabs += "\t"}
    while (Spaces.length < Math.abs(inp[1].value)){Spaces += "\x20"}
    TbSp = Tabs + Spaces;
    v = txt[0].value;
    for (i = 0; i < v.length; i++){c = v.charAt(i);
    switch (c){
    case  "\x09" : s = "\\t";
    break;
    case  "\x0A" : s = "\\n\" + " + "\r\n" + TbSp + "\"";
    break;
    case  "\x0D" : s = "\\r";
    break;
    case  "\x22" : s = "\\\"";
    break;
    case  "\x2F" : s = "\\/";
    break;
    case  "\x5C" : s = "\\\\";
    break;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default : s = c;
    break;}
    ss += s;}
    vName = inp[2].value;
    txt[1].value = TbSp + "var " + vName + " = " + "\r\n" + TbSp + "\"" + ss + "\"\x3B";
    txt[1].select();}
    </script>
    <style type="text/css">
    p{white-space:nowrap}
    textarea{width:100%;height:150px;overflow:scroll;
    word-wrap:normal}
    input{width:100px;margin-right:20px;vertical-align:middle;text-align:center}
    div{text-align:right}
    button{padding-left:10px;padding-right:10px}
    </style>
    </head>
    <body>
    <form id="f" action="">
    <p style="margin-bottom:0">
    <label>Paste: html-source</label><br><textarea cols="95" rows="10"></textarea><br>
    </p>
    <div><button onclick="document.getElementById('f').reset();return false;">Reset</button></div>
    <p style="text-align:center">
    <label>indent # Tabs: </label><input value="0">
    <label>indent # Spaces: </label><input value="0">
    <label>variable Name: </label><input value="sCode">
    </p>
    <p>
    <button  onclick="srcEscape();return false;">Convert</button><br>
    <textarea cols="95" rows="10"></textarea><br>
    <label>Copy: js-code</label>
    </p>
    </form>
    </body>
    </html>
    Last edited by swmr; 11-04-2003 at 06:50 AM.
    hmm... ?


 

Posting Permissions

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