Web Analytics Made Easy -
StatCounter filename - CodingForum

Announcement

Collapse
No announcement yet.

filename

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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 /).
    De gustibus non est disputandum.

    Comment


    • #3
      thanks. it works just fine

      Comment

      Working...
      X