In javascript/jquery, given a string of a url, how can I check if it is a url to a file or a directory?
Thanks
In javascript/jquery, given a string of a url, how can I check if it is a url to a file or a directory? Thanks |
|||
|
You can't, because there's no difference in HTTP. A URL is neither a "file" nor a "directory." It's a resource. When requesting that resource, the server responds with, well, a response. That response consists of headers and content. A header (such as And any resource can return any response that the server wants. For example, you might request Even if you ask for a "directory" from your point of view, the server is still responding with headers and content. That content may take the form of a directory listing, but it's indistinguishable from any other successful response aside from parsing the content itself. If you're looking for something which the server has indicated is a "file" then you're looking for the |
|||
|
Like David said, you can't really tell. But if you want to find out if the last part of a url has a '.' in it (maybe that's what you mean by a "file"?), this might work:
|
|||
|