javascript/jquery得到的网址没有散列

问题描述:

我知道我可以用javascript/jquery读取URL的散列值。但是有可能我可以读取尾随位?查找网址的最后一部分javascript/jquery得到的网址没有散列

我有一个域名。 http://www.blah.com/ 域的每个部分驻留在一决高下,如“此页”的例子

http://www.blah.com/service/ (带或不带尾随斜杠)的URL下,但我想知道我是否可以在网址中找到“服务”与JavaScript,没有服务器端干预。我知道我能做到这一点,如果我有 http://www.blah.com/#service

我不知道我只是好奇,我真的不知道我会看什么,否则,所以这是我的第一站,在我的搜索,因为我无能。 。

var p = location.pathname; 
p = p.substring(p.length-1) == '/' ? p.substring(0, p.length-1) : p; 
p.split('/').pop(); 

使用正则表达式:

last_bit = $(location).attr('href').replace(/https?:\/\/[^\/]+/i, "");