You are viewing this page out of context. To see it in the context it is intended please click here.
About This Page
Reply posted by Bill Tarr on Sat 22 Feb 2003 in response to Opening database relative URLs in JavaScript
Re: Perfect compromise
This is a flexible version of this code I just wrote. It's supposed to returndifferent parts of the URL based on your needs.. might be overkill for most
people *shrug*
function getPath ( part ) {
// Purpose: return the requested URL Path from the document URL
// Called: Helper function
var path = "";
var arrProtoSplit = document.URL.split('://');
var arrSlashSplit = arrProtoSplit [ 1 ].split ( '/' );
for ( var x = 1; x < arrSlashSplit.length; x++ ) {
if ( arrSlashSplit [ x ].indexOf ( '.nsf' ) != '-1' ) { db =
arrSlashSplit [ x ] ; break; }
else { path = path + arrSlashSplit [ x ] + "/"; }
}
if ( part == "proto" ) return arrProtoSplit [ 0 ]
else if ( part == "serverName" ) return arrSlashSplit [ 0 ]
else if ( part == "path" ) return path
else if ( part == "dbName" ) return db
else if ( part == "thisServer" ) return arrProtoSplit [ 0 ] + "://" +
arrSlashSplit [ 0 ]
else if ( part == "thisDB" ) return arrProtoSplit [ 0 ] + "://" +
arrSlashSplit [ 0 ] + "/" + path + db
else return document.URL
}