Javascript get url page name.

In this article, I will explain  how to get page name from url in javascript.We are using following JavaScript code to get url page name using javascript.The filename is the last part of the URL from the last trailing slash ('/').
Suppose,My URL is and i want to get page name pagename.html
Example:Getting url page name using Javascript
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>getting url page name using Javascript</title>
<script language="javascript">
        var url = window.location.pathname;//get an url
        var pageName = url.substring(url.lastIndexOf('/') + 1);    


You can now get the current url pagename using the above code.I hope,this example will help you to get url page name using JavaScript.