using window.location.pathname

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • superunknownman
    New Member
    • Mar 2008
    • 1

    using window.location.pathname

    I was trying to capture the pathname only when using

    var from= window.location .pathname;

    and I want to lose the filename. Is there another way for me to get just the path?
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    Code:
    function Path() {
        var tob = {href:window.location.href.toString()};
        tob.domain = document.domain;
        var lr = tob.href.toString().split(/[\/\\]/g);
        var tqs = window.location.search;
        tob.qs = tqs ? tqs : "";
        tob.file = lr.last();
        tob.path = lr.slice(0, -1).join("/") + "/";
        tob['char'] = document.characterSet;
        tob.ext = tob.file.match(/(?:\.)[\d\w]{0,4}/)[0];
        return tob;
    }
    alert(Path().path)

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      or-
      var url=location.hr ef.replace(/\\/g,'/');
      alert(url.subst ring(0,url.last IndexOf('/')))

      (You only need the replace for local files on windows)

      Comment

      Working...