SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: url embedding

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    url embedding

    Hello - I was wondering if anyone had any examples of javascript being used to automatically recognize url's in a textfield and convert them into active links. Just like what the 1st checkbox below this very textbox does. I have some text going into a database and I was hoping to use javascript to automatically find the links and convert them before the text gets posted to the db. Any help greatly appreciated. Thanks!

    Ian
    signature

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this might be better done server side, other wise play about with this

    PHP Code:
    Function switchBreaks() {
      var 
    taInput;
      var 
    sNewString;

      
    taInput yourForm.yourTextArea.value;
      
    sNewString taInput.replace(/[\n\r]+/g,'<br>');
      
    alert(sNewString);

    or
    PHP Code:
    <html>
    <
    head>
    <
    title></title>

    <
    script>
    <!--     
        Function 
    stringReplace(originalStringfindTextreplaceText)
        {     
            var 
    pos 0;
            var 
    Len findText.length;
            
    pos originalString.indexOf(findText);
            
            While (
    pos != -1)
            {
                
    preString originalString.substring(0pos);
                
    postString originalString.substring(pos LenoriginalString.length);
                
    originalString preString replaceText postString;
                
    pos originalString.indexOf(findText);
            }         
            Return 
    originalString;
        }
    //-->
    </script>
    </head>

    <body>

    <script>
    <!--

    var origString = New String('Lol @ Sphinx the Sphinx A New Webmaster:P');
    var findString = New String('Lol @ Sphinx the Sphinx');
    var replaceString = New String('theSphinx');
    var resultString = stringReplace(origString, findString, replaceString)

        With (document)
        {
            write('<pre>')
            write('original String : ' + origString.bold()        + '<br>');
            write('searched        : ' + findString.bold()            + '<br>');
            write('replaced        : ' + replaceString.bold()         + '<br>');
            write('result          : ' + resultString.bold()                  );
            write('</pre>')
        }
    //-->
    </script>

    </body>
    </html> 
    as i dont have time to give you a proper example

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right on, thank you very much - i'll check that out!
    signature


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
  •