Javascript...
GHoosdum
Icrontian
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?
0
Comments
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)
I've never done it and I didn't even try the code that I gave you.
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.
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()