SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Q: Take end part of document.referrer

    If I have the url 'http://www.myurl.com/section/about_us.php' is there a way (I'm thinking the best is via document.referrer) to only grab 'about_us.php' I'm thinking if there was a way to take everything from the end to the first / then it would work. Is something like this possible?

    I basically want to grab my content pages so I can stick them in a different interface and to do this I need just the end part of the url.

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm thinking if there was a way to take everything from the end to the first / then it would work. Is something like this possible?
    Yep:
    Code:
    var str = 'http://www.myurl.com/section/about_us.php';
    var start = str.lastIndexOf("/") + 1;
    var page = str.substring(start);
    alert(page);

  3. #3
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet! Thanks for the help .

  4. #4
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is another way that will allow you to gain a millisecond )
    Code:
    var str = 'http://www.myurl.com/section/about_us.php';
    var page = str.split("\/")[str.split("\/").length-1]
    alert(page);

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpaceFrog
    Here is another way that will allow you to gain a millisecond
    Using FF1.0, on my system my method is twice as fast as yours, and of course yours is probably incomprehensible to a beginner, so I'm going to have to dock you 10pts for speed of execution, and 10pts for clarity.

  6. #6
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well at least my method allows also to retrieve every folder level of path ...
    how many points is that worth ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •