Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Hyperlinking Plain Text
 
  chubbard posted this script:
  Below is a function that searches plain text, or text with minimal HTML formatting, for occurrences of 'http://', and creates hyperlinks around these.  Great for things like discussion boards where people are sharing URLs for further investigation:

function AutoLink(str)
    {
    var ch;
    var i, iEnd;
    var strLink;
    var strRet = "";
    var strFmt = '<a href="|LINK|" target="_blank">|LINK|</a>';

    while ((i = str.indexOf("http://")) != -1)
        {
        iEnd = i + 7;
        ch = str.charAt(iEnd);
        while (ch != "" && ch != " " && ch != "\n" && ch != "\"" && ch != "<")
            ch = str.charAt(++iEnd);
        strLink = str.substring(i, iEnd);
        strRet += str.substring(0, i);
        if (strRet.replace)
            strRet += strFmt.replace("|LINK|", strLink);    // v2.0
        else
            strRet += strFmt.split("|LINK|").join(strLink); // v1.0
        str = str.substring(iEnd, str.length);
        }
    strRet += str;

    return strRet;
    }

Here is one way it can be used:

webcall function TestAutoLink()
    {
    var rs = new ResultSet("Comments", "Comments", "*");
    if (rs.next())
        response.write(AutoLink(response.encodeHTML(rs.Comments, true)));
    }

Note that response.encodeHTML() is called before the AutoLink() function.  This turns newlines, "\n", into "<br>\n" for HTML output, but if it is called after AutoLink(), it would also encode the <a> tags into "&lt;a&gt;" so that they would show up as text in the output, instead of hyperlinking the text inside the <a> tag.
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us