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.
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.
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 ...
I am using 'if (filename == "") then filename = "index" ' as a stop-gap.