Javascript get url page name
Posted by Raj
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 http://example.com/pagename.html and i want to get page name pagename.html
Example:Getting url page name using Javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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);
alert(pageName);
</script>
</head>
<body>
</body>
</html>
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.
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 http://example.com/pagename.html and i want to get page name pagename.html
Example:Getting url page name using Javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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);
alert(pageName);
</script>
</head>
<body>
</body>
</html>
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.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
current page name,
get an url,
get parameters from url,
get url parameters,
getting url,
getting url,
JAVASCRIPT,
location path name
.You can leave a response, or trackback from your own site.