Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript Question

  • 21-08-2002 07:24PM
    #1
    Registered Users, Registered Users 2 Posts: 55,735 ✭✭✭✭


    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, Registered Users 2 Posts: 3,890 ✭✭✭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, Registered Users 2 Posts: 55,735 ✭✭✭✭Mr E


    Perfect!

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

    - Dave.


Advertisement