Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: filename

  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    filename

    hi,
    i have a page called page1.htm and i would like to use the page1 name within the document itself (i mean the page1.htm) so that i don't have to write page1 everytime

    i would like to use it in this line:
    <script language="javascript" src=page1.js></script>

    i have multiple pages and the .js filename is always the same as the .htm filename.

    could that be replaced with +filename+ or something like that (i'm just guessing here so don't laugh

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try

    <script>
    var file = location.pathname;

    document.write("<script language=\"javascript\" src=\"" + file.substring(file.lastIndexOf("/") + 1, file.lastIndexOf(".")) + ".js\"><\/script>");
    </script>

    Note: This works only correct if you call the file from the server, not when you open it from the file system of Windows ('cause Windows use \ instead of /).

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks. it works just fine


  •  

    Posting Permissions

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