get filename from url js

JavaScript
var filename = location.pathname.substr(location.pathname.lastIndexOf("/")+1);

Source

Also in JavaScript: