470,573 Members | 1,666 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

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?
Mar 10 '08 #1
2 9824
rnd me
427 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. function Path() {
  2.     var tob = {href:window.location.href.toString()};
  3.     tob.domain = document.domain;
  4.     var lr = tob.href.toString().split(/[\/\\]/g);
  5.     var tqs = window.location.search;
  6.     tob.qs = tqs ? tqs : "";
  7.     tob.file = lr.last();
  8.     tob.path = lr.slice(0, -1).join("/") + "/";
  9.     tob['char'] = document.characterSet;
  10.     tob.ext = tob.file.match(/(?:\.)[\d\w]{0,4}/)[0];
  11.     return tob;
  12. }
  13. alert(Path().path)
  14.  
  15.  
Mar 10 '08 #2
mrhoo
428 256MB
or-
var url=location.href.replace(/\\/g,'/');
alert(url.substring(0,url.lastIndexOf('/')))

(You only need the replace for local files on windows)
Mar 11 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Japhy | last post: by
10 posts views Thread by Hughes | last post: by
3 posts views Thread by Rob | last post: by
12 posts views Thread by Don Juan | last post: by
18 posts views Thread by len.hartley | last post: by
2 posts views Thread by find clausen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.