SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast intheory's Avatar
    Join Date
    Jun 2004
    Location
    Overland Park, KS
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding URLs, converting to hyperlinks

    I'm using a commercial CMS product that has a few quirks I'm trying to overcome with JS, as I can't modify the way some elements render.

    My scenario is that users can enter a URL as part of their profile, and that data can be displayed on their profile page. But there's no way with the CMS for me to make that URL a hyperlink. I also don't have any field validation control over what the user enters. So someone may enter blogger.com, someone else may put www.blogger.com, etc.

    I'm looking for a way to search a specified DIV for text strings that look like URLs, then rewrite the HTML/append additional HTML around that string with the appropriate <a href="$1">$1</a> code to make that URL a hyperlink.

    Is this just rediculously hard? Let's assume I can get the regex statement correct for the javascript to parse through my div and find URLs. Is it then even possible to pull that string and rewrite HTML using javascript the way I'm thinking?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've found this but as most i've found they all rely on some user training.

    Not all URL's will be converted, and only if it starts with HTTP:// will this one work.

    http://www.mikezilla.com/exp0034.html

    Unless you do some mass changing to do further checks.


  3. #3
    SitePoint Enthusiast intheory's Avatar
    Join Date
    Jun 2004
    Location
    Overland Park, KS
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks gRoberts, that gives me a good start.


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
  •