...

View Full Version : getting the name of the first folder in a breadcrumb trail



garry70
06-17-2008, 10:28 AM
I need some code in Javascript that gets the name of the top level folder that's at the root directory of the current page.

So for example, if I am at a page called mywebsite.com/folder1/folder2/folder3/index.hmtl ,I want to be able to get the name of folder1.

Any ideas please?

Cheers,

Garry

garry70
06-17-2008, 02:05 PM
hi,

i'm trying to get the name of the first folder in the structure root of the current page. how do i do this?

thannks

Kor
06-17-2008, 02:38 PM
var firstFolder=location.href.split('/')[3];

liorean
06-17-2008, 02:56 PM
Split the URI string on the solidus character, then ignore the first three parts (the URI scheme 'http:' usually, an empty string '', and the domain name respectively). The first one after that will be the first of those directories, and so on. (You might want to throw away anything that appears after a question mark in the URI as well, if you're using GET requests with query parameters anywhere on the site.)

Kor
06-17-2008, 03:02 PM
Please, don't cross post:
http://www.codingforums.com/showthread.php?t=142211

liorean
06-17-2008, 03:07 PM
Please, don't cross post:
http://www.codingforums.com/showthread.php?t=142211Except I merged the threads here, so that one is gone.


Still, garry70: Please don't post in the Post a JavaScript forum unless you have a finished and useful script to share with the world. Please don't post the same question three times, once is enough. And if you notice you're not asking it in the right forum, please ask a moderator for the forum you posted it in to move it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum