Parse URL with Javascript
You can use
var pagenum = location.pathname.match(/\/page\/(.*)/)[1];
It will extract anything past '/page/' in your URL;
Checkout this package jsuri
Or keep it simple http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
URI.js is a library for working with URLs. It can not only parse URLs, but also offers a simple fluent API (jQuery like) for modifying URLs.
Take a look at the documentation on the location object http://www.w3schools.com/jsref/obj_location.asp
You first want the "pathname" part, location.pathname