getFolderName SiteCatalyst Plug-in

The getFolderName plug-in captures a folder name from the URL of a web page. Once captured, the value can be populated into any other JavaScript variable.

Plug-in Prototype
s.getFolderName(f)

Parameter Descriptions
f=number of which folder in the URL that is to be captured.

Example
Here is an example use of the plug-in to populate a s.prop variable with the name value of the folder noted in the function call.

For the URL webanalyticsland.com/apple/orange/pear/index.php

s.prop1=s.getFolderName(1); — would return apple
s.prop1=s.getFolderName(2); — would return orange
s.prop1=s.getFolderName(3); — would return pear

Code

/*
 * Plugin getFolderName
 */
s.getFolderName=new Function("n","" 
+"var p=s.wd.location.pathname.substring(0, document.location.pathname.lastIndexOf('/') + 1),pa=p.split('/');if(pa[0]==''){for(var " 
+"i=0;i<pa.length;i++){pa[i]=i!=pa.length?pa[i+1]:null;}}return n?pa[" 
+"parseInt(n)-1]:'';");