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?
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.
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...
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.
Bookmarks