Javascript...

GHoosdumGHoosdum Icrontian
edited March 2005 in Internet & Media
I'm a moron when it comes to javascript. However, for a specific application I need to edit a javascript script that's already been written, so I need a little guidance. What I'm trying to do is parse the URL and feed in the file name of the current page (just the file name, not the full path) into a variable. Is this possible?

Comments

  • a2jfreaka2jfreak Houston, TX Member
    edited March 2005
    Find the last instance of / and grab all the characters after.

    filename = document.location;
    filename = filename.substring(filename.lastIndexOf("/"),filename.length);

    (I think that will work . . . if not, perhaps filename.length - 1, or filename.lastIndexOf("/") + 1)
  • GHoosdumGHoosdum Icrontian
    edited March 2005
    Thanks, a2j, I'll try it.
  • a2jfreaka2jfreak Houston, TX Member
    edited March 2005
    Lemme know.

    I've never done it and I didn't even try the code that I gave you.
  • GHoosdumGHoosdum Icrontian
    edited March 2005
    It didn't work.

    However, I don't know what I'm doing wrong, but no matter what string-based operation I tried to perform (split, indexOf, lastIndexOf) I got an error on page load:
    "Error Line x: Object does not support property or method" Where x was the line number of whatever line in my code contained a string operation. :(
  • sharkydartsharkydart KY Icrontian
    edited March 2005
    try location.pathname instead of document.location - not sure if it will make a difference...

    also - when you say filename = document.location, are you sure filename is made a string and not some kind of object pointer? i'm not very familiar with javascript, but i know i like knowing what type something will be when i create it. try declaring it as a string, then setting it equal to location.pathname and see if that works. are you ending the calls with open and closed parentheses? that might be the cause also.
    ...location.pathname()
Sign In or Register to comment.