Current Page with JavaScript

Avatar of Chris Coyier
Chris Coyier on

This is like a replacement for PHP’s SCRIPT_NAME with JavaScript.

location.href.split('/').pop();

For example with this URL:
https://css-tricks.com/examples/ScriptName/index.php

This code:

document.write( location.href.split('/').pop() );

Would write to the page: “index.php”