www.webdeveloper.com
Results 1 to 5 of 5

Thread: filename.html missing from location.href

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    filename.html missing from location.href

    When at the root of a site, without specifying a filename, a usual default of index.html (or even .htm) is loaded; however index.html does not appear in the location.href or location.pathname properties - only what you see in the browser address bar.
    I only have access to client-side Javascript (no server-side stuff at all).

    Is there a way of getting this default filename from client-side JavaScript?

  2. #2
    Join Date
    Dec 2008
    Posts
    488
    If the filename is missing, it will always be the same, right? Assuming you're not using PHP or ASP, it should always be "index.html", so if you're trying to extract a filename from location.href, and none is returned, then simply use a default.

    If you are using ASP or PHP, then you can simply output the filename as a variable in the script somewhere on your page using the server functions.

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by HarryAlffa View Post
    Is there a way of getting this default filename from client-side JavaScript?
    no. while index.html is common, i've seen default.asp, index.htm, default.shtml, and many others and furthermore, it can be almost anything with a custom config.

    also, not all pages correspond to files. i've been working a lot in node.js recently, and it doesn't map file to urls at all...

    what you have client side is what you see in firebug. period.

    why do you need the filename? "/" works just fine for ajax...

  4. #4
    Join Date
    Jul 2011
    Posts
    2
    Hi Guys,
    Thanks for the replies.
    I'm saving the scroll position of a div in a cookie so that it can be retrieved and set when moving between pages. I use the filename to get the correct value for the correct page.

    If you assume that it's only the root of the domain which will return no filename, then (for my purposes) any string will do as an identifier, as long as it's unique, but ...

    Is there a way for client-side JavaScript to get that info from the server?

    I am using 'if (filename == "") then filename = "index" ' as a stop-gap.

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    use urls instead of files names. every page already has a unique one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles