Forum Moderators: open
I can use:
unescape(window.location.pathname)
to give me the complete path but instead of:
[domain.com...]
my code needs just:
filename.htm.
I've looked for a similar command to return the filename, but so far been unsuccessful.
I really hope that there is a simpler way to do this than searching for slashes and chopping up strings etc.
for as the path's are concerned you can try this out,
if the path is like for eg:xyc/abc/filename.htm
so it can be ../../filename.htm
The way I understand the question, rpking is looking for a snippet of javascript code that he can run on any page and have it automatically return the filename of the page for whatever page is currently running it.
It's true, as you said, that the path can be written in several ways. But I'm not clear how that helps find the filename his code needs.
<SCRIPT LANGUAGE=javascript>
<!--
var tr = window.location.pathname
len = tr.length
rs = 0
for (i = len; i > 0; i--) {
vb = tr.substring(i,i+1)
if (vb == "/" && rs == 0) {
document.write('<hr>' + tr.substring(i+1,len))
rs = 1
}
}
//-->
</SCRIPT>