Closed Thread Icon

Topic awaiting preservation: Getting the file name (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8182" title="Pages that link to Topic awaiting preservation: Getting the file name (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Getting the file name <span class="small">(Page 1 of 1)</span>\

 
viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 05-23-2002 18:11

If I use the function "window.location.href" I get something like:
...../.../.../filename.htm

Is there an easy way to get only the name of the filename, or I must parse the result of window.location.href to get it?

I want something like:
"window.location.xxxx" giving me this result: "filename.htm", NOT the whole URL.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-23-2002 20:13

window.location.filename

will give you the path and file name:

/examples/example.html

for example. Then you have to use some sort of regular expression on it, or the indexOf function, to find where the last '/' is and give you everything after that.

viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 05-23-2002 21:41

I've tried the window.location.filename instruction and it returns "undefined".
I'm starting to hate this word... it keeps following me all the time :-)
So, I'm doing what you said, using indexOf(), actually, I'm using lastIndexOf().
It goes like this:
lastslash = window.location.href.lastIndexOf ("/");
Funny thing is that my literature doesn't explain that the second parameter of lastIndex() can be omitted. I found it by chance because I mistyped "window.location.href.length", that was supposed to be the second parameter, and it made no difference to the final result.
Then, using substring() I could take only the part I wanted.

P.S. - btw, how do I do to make those codes in between bars, when posting code here?


Jestah
Maniac (V) Mad Scientist

From: Long Island, NY
Insane since: Jun 2000

posted posted 05-23-2002 21:57

I assume you mean quotes:

[quote.] text [/quote].

You need to remove the periods though. For a complete listing of the UBB code look to the left side of the text box when responding

-Jestah
Cell 277

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-24-2002 01:43

Ah, glad you figured it out. BTW, if you don't know, the second parameter in substr can also be left out.

Now, location.href is a *little* unsafe to use, because it could mess up with something like
http://www.blah.com/something.html#a/b

So, if we can get location.filename to work, that'd be good. I probably just gave you the wrong property... oh yeah, I remember now, I meant location.pathname, not filename. Use that.

Using lastIndexOf was a good call.

« BackwardsOnwards »

Show Forum Drop Down Menu