Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript Question

Options
  • 21-08-2002 7:24pm
    #1
    Registered Users Posts: 55,519 ✭✭✭✭


    Hi all,

    I need to get a particular part of a URL using javascript.
    For example, take the following URL:

    http://www.domainxyz.com/dir1/dir2/index.aspx?mode=edit&token=1x7g4sa032

    What I need is the "index" part of the URL (i.e. the filename, minus the URL before it, or the extension (.aspx), or the parameters).

    Do I need to get document.location and hack it with string functions? Or is there a better way?

    - Dave.


Comments

  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    Originally posted by TmB

    Do I need to get document.location and hack it with string functions? Or is there a better way?

    Yeah thats the way I use anyway. You can narrow down what to search on by using document.locaiton.pathname...

    var ext = document.location.pathname.substring( document.location.pathname.lastIndexOf( "." ) );
    var base = document.location.pathname.substring( document.location.pathname.lastIndexOf( "/" ) + 1, document.location.pathname.lastIndexOf( "." ) );


  • Registered Users Posts: 55,519 ✭✭✭✭Mr E


    Perfect!

    Thanks a million..... I'll give that a go this morning.

    - Dave.


Advertisement