views:

59

answers:

1

I have a url that looks like this : http://mysite.com/1/2/Simpson and I want to create a variable that contains just Simpson...

Not sure how to do it here...

I have:

var myvar = window.location.pathname

and have tried something using substring, but can't seem to get it to work?

+1  A: 

this may work, but you might as well use the string window.location.href, not the object window.location (which contains many different objects within it):

var dirs = window.location.href.split( '/' );

however, there is a window.location.pathname that you could split, too. it just depends on if you want the part in front of the first "/" to be in the arrays as well (http://mysite.com).

var dirs = window.location.pathname.split( '/' );
Dan Beam