/ Published in: JavaScript

Get current page name (file name) with extension (if any).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function GetCurrentPageName(){ var url = window.location.pathname; var urlLength = url.length; var lastSlashLocation = url.lastIndexOf('/'); //Make sure the last char in the path isn't '/' if (urlLength - lastSlashLocation <= 1) url = url.substring(0,lastSlashLocation); var pageName = url.substring(url.lastIndexOf('/') + 1); return pageName; }
Comments
