Small Javascript to count the level of sub directories

Hi there!
i was looking for a javascript code to get the level of the browser location with javascript. I could not find anything usefull therefor I’ve written a piece of code. I hope you find it usefull. This script will output the exact number of directories you are in.
ie.

  • http://www.yourdomain.com/ -> 0
  • http://www.yourdomain.com/dir1/dir2/dir3/ ->3
  • var TheURL = location.href;
    var CleanUp = TheURL.replace(/http:\/\/([0-9a-zA-Z._])*\//,"")
    var TheDir = CleanUp.split("/")
    var TheCount = TheDir.length-1
    
    document.write(TheCount)
    

    Leave a comment if you think this code was usefull.

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Facebook
    • Google
    • Furl
    • Live
    • Ma.gnolia
    • NewsVine
    • StumbleUpon
    • Technorati
    • TwitThis
    • Chawlk
    • Propeller
    • Ycombinator
    Tags:

    Leave a Reply