5

Trying to get the aspx name from the current page from javascript?

1

4 Answers 4

9

Try this

<script language="javascript">  
        var url = window.location.pathname;  
        var myPageName = url.substring(url.lastIndexOf('/') + 1);      
        alert(myPageName);  
</script>  
Sign up to request clarification or add additional context in comments.

Comments

2

As an alternative -

var page = '<%=Path.GetFileName(Request.Path)%>'

Do you want to parse the current window, or rely on asp.net? Both work - it's up to you.

Comments

0

To Get The Exact Formname using jquery one can do string manipulation as shown.

    $(document).ready(function () {
    var path = window.location.pathname;
    var page = path.substr( path.lastIndexOf("/") + 1 ).split(".",1);
    var formname=page[0].toString();
    alert(formname);
    });

Comments

0

This one without the query string

$(function () {
    var url = window.location.pathname;  
    var pageQuery = url.substring(url.lastIndexOf('/') + 1);
    var page = pageQuery.split('?')[0];
)}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.