2010/01/24

Javascript to Grab Last Part of the document.url

stackoverflow.com 有範例,例如:

var lastPart = window.location.href.split("/").pop();

但遇到 http://example.com/test/action?foo=bar 之類的網址,想避免抓成 action?foo=bar 的結果,就該使用 location.pathname.split('/').pop(); 的方式。