CFLib.org – Common Function Library Project

GetAnchorFromURL(this_url)

Last updated February 22, 2002

author

Shawn Seley

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns the page anchor for the supplied URL. If no anchor is found, then returns an empty string. Works with the http protocol where page anchors follow the "filename#anchor" syntax.

Return Values:
Returns a string.

Example:

<cfoutput>
#GetAnchorFromURL("http://somehost.com/dir1/dir2/filename.htm##anchor")#<br>
#GetAnchorFromURL("filename.htm##anchor")#<br>
#GetAnchorFromURL("filename.htm##")#<br>
#GetAnchorFromURL("filename.htm")#<br>
#GetAnchorFromURL("../filename.htm##anchor")#<br>
</cfoutput>

Parameters:

Name Description Required
this_url URL to parse. Yes

Full UDF Source:

/**
 * Returns the page anchor from a specified URL.
 * 
 * @param this_url      URL to parse. 
 * @return Returns a string. 
 * @author Shawn Seley (shawnse@aol.com) 
 * @version 1, February 21, 2002 
 */
function GetAnchorFromURL(this_url) {
    var re_found_struct = "";
    
    this_url = trim(this_url);
    
    re_found_struct = REFind("##[^\?]*", this_url, 1, "True");
    
    if (re_found_struct.pos[1] GT 0) {
        return Mid(this_url, re_found_struct.pos[1]+1, re_found_struct.len[1]-1);
    } else return "";
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson