Get page name from url in javascript

In this tutorial you will learn how to get page name from url in javascript. I have already written a post that teaches same thing and in asp.net. I will recommend you to get page name from url by using client side language such as javascript. Try to write as less server side code as possible because if same thing can be achieved through client side language javascript then there is no need to write server side code and put burden on server. Now let's have a look over how to do so

Get page name from url in javascript.

<script language="javascript">
        var url = window.location.pathname;

        var myPageName = url.substring(url.lastIndexOf('/') + 1);    

        alert(myPageName);
</script>



So this is the way to get page name from url in javascript.


Happy Coding, Keep Coding.



0 comments: