Click here to Skip to main content
15,903,012 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Not allow to save a web page Pin
alex.barylski24-Jul-04 13:38
alex.barylski24-Jul-04 13:38 
GeneralRe: Not allow to save a web page Pin
TrungHuynh24-Jul-04 15:47
TrungHuynh24-Jul-04 15:47 
GeneralRe: Not allow to save a web page Pin
Bee Master25-Jul-04 3:52
Bee Master25-Jul-04 3:52 
GeneralJScript VS JScript.NET Pin
alex.barylski24-Jul-04 11:07
alex.barylski24-Jul-04 11:07 
GeneralRe: JScript VS JScript.NET Pin
Rocky Moore24-Jul-04 11:38
Rocky Moore24-Jul-04 11:38 
GeneralJavascript regex to strip tag Pin
alex.barylski23-Jul-04 18:12
alex.barylski23-Jul-04 18:12 
GeneralRe: Javascript regex to strip tag Pin
alex.barylski24-Jul-04 9:58
alex.barylski24-Jul-04 9:58 
GeneralRe: Javascript regex to strip tag Pin
Richard Deeming5-Aug-04 8:30
mveRichard Deeming5-Aug-04 8:30 
Try something like this:
JavaScript
/// <summary>
/// Strip HTML tags from a string.
/// </summary>
/// <param name="value">The string to parse</param>
/// <param name="exclude">
/// True to keep specified tags; 
/// False to strip only the specified tags;
/// </param>
/// <param name="tagsToExclude">The tags to keep / strip</param>
/// <returns>The parsed value</returns>
function stripTags(value, exclude, tagsToExclude)
{
    if ("string" != typeof(value) || 0 == value.length) return "";
    if ("boolean" != typeof(exclude)) exclude = true;
    
    var arrTags = null;
    var tagCount = 0;
    
    switch(typeof(tagsToExclude))
    {
        case "object":
            // Passed an array of tags
            if (Array == tagsToExclude.constructor)
            {
                tagCount = tagsToExclude.length;
                if (0 == tagCount)
                {
                    // Possibly a sparse array?
                    arrTags = new Array();
                    for(var key in tagsToExclude)
                    {
                        arrTags.push(tagsToExclude[key]);
                        tagCount++;
                    }
                }
                else
                {
                    arrTags = tagsToExclude;
                }
            }
            break;
            
        case "string":
            // Possibly passed multiple tags as optional parameters
            var len = arguments.length;
            tagCount = len - 2;
            arrTags = new Array(tagCount);
            arrTags[0] = tagsToExclude;
            for(var i = 3; i < len; i++)
            {
                arrTags[i - 2] = arguments[i];
            }
            break;
    }
    
    // If we're specifying tags to strip, and
    // we haven't specified any tags, return
    if (!exclude && 0 == tagCount) return value;
    
    // Match an opening or closing tag
    // Capture the tag name to group 1
    var reTag = /<\/?([a-z0-9]+)[^>]*>/gi;
    
    if (0 == tagCount)
    {
        // Strip all tags
        return value.replace(reTag, "");
    }
    else if (exclude)
    {
        return value.replace(reTag, function($0, $1)
        {
            var tagName = $1.toLowerCase();
            var found = false;
            for(var i=0; i < tagCount && !found; i++)
            {
                if (arrTags[i] == tagName) found = true;
            }
            
            return found ? $0 : "";
        });
    }
    else
    {
        return value.replace(reTag, function($0, $1)
        {
            var tagName = $1.toLowerCase();
            var found = false;
            for(var i=0; i < tagCount && !found; i++)
            {
                if (arrTags[i] == tagName) found = true;
            }
            
            return found ? "" : $0;
        });
    }
}

value = stripTags(value, exclude, "p", "b", "i", "iframe");
// -or-
// value = stipTags(value, exclude, ["p", "b", "i", "iframe"]);



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Generaldetecting when a button is pressed Pin
kyleiscool200423-Jul-04 9:32
kyleiscool200423-Jul-04 9:32 
GeneralRe: detecting when a button is pressed Pin
alex.barylski23-Jul-04 18:51
alex.barylski23-Jul-04 18:51 
GeneralRe: detecting when a button is pressed Pin
Anonymous30-Jul-04 7:39
Anonymous30-Jul-04 7:39 
GeneralFrames Pin
kyleiscool200423-Jul-04 9:26
kyleiscool200423-Jul-04 9:26 
GeneralRe: Frames Pin
alex.barylski23-Jul-04 18:53
alex.barylski23-Jul-04 18:53 
GeneralNavigate from Child to Parent Pin
KKCodePro22-Jul-04 16:06
KKCodePro22-Jul-04 16:06 
GeneralRe: Navigate from Child to Parent Pin
alex.barylski23-Jul-04 18:55
alex.barylski23-Jul-04 18:55 
GeneralOCX / Cab / CODEBASE Pin
RichardGrimmer22-Jul-04 2:40
RichardGrimmer22-Jul-04 2:40 
GeneralRe: OCX / Cab / CODEBASE Pin
OBRon22-Jul-04 5:10
OBRon22-Jul-04 5:10 
GeneralRegular Expressions Pin
jazz081521-Jul-04 5:01
jazz081521-Jul-04 5:01 
GeneralRe: Regular Expressions Pin
Javier Lozano22-Jul-04 14:14
Javier Lozano22-Jul-04 14:14 
GeneralTextArea and &lt;HTML&gt; tag Pin
devvvy20-Jul-04 20:13
devvvy20-Jul-04 20:13 
GeneralRe: TextArea and &lt;HTML&gt; tag Pin
alex.barylski23-Jul-04 18:49
alex.barylski23-Jul-04 18:49 
GeneralClientSide JavaScript HTML Tag Pin
gmhanna20-Jul-04 18:20
gmhanna20-Jul-04 18:20 
GeneralRe: ClientSide JavaScript HTML Tag Pin
alex.barylski23-Jul-04 18:50
alex.barylski23-Jul-04 18:50 
GeneralRe: ClientSide JavaScript HTML Tag Pin
mysorian16-Aug-04 16:43
professionalmysorian16-Aug-04 16:43 
GeneralCalculating Variance excluding non-working days Pin
Ph@ntom20-Jul-04 17:03
Ph@ntom20-Jul-04 17:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.