Results 1 to 3 of 3

Thread: Vb -> JS

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    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
    < o >

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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]); 
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width