-
Vb -> JS
Hi, I'm fairily new to Javascript and not too good in it. I want to make a script that prints the name of the file on the page. ex: it's located at http://www.blah.com/dir/page.html and i want the page to say "page". I have this code from VB, which does the trick:
Code:
URL=Replace(URL,".html","")
URL=Replace(URL,".htm","")
For a& = Len(URL) To 1 Step -1
If Mid(URL, a, 1) = "/" Then
b$ = Mid(URL, a + 1, Len(URL) - a)
MsgBox b
End
End If
Next a
Can anyone give me the Javascript equivilant? or something that accomplishes what i described above?
Thanks
-George
-
Code:
<script type="text/javascript">
re = /^.*\/(.*)\.[a-zA-Z]+$/;
result = re.exec(document.location);
alert(result[1]);
</script>
is one way of doing it using a regular expression.
-
And if you want to win an obfusicated code contest, you can do that in one line:
PHP Code:
alert(/^.*\/(.*)\.[a-zA-Z]+$/.exec(document.location)[1]);