Reputation: 11
In my online shop I have some links in product pages which go to a template which the user can download. Unfortunately, as I have many of these links, some are broken, because the file is missing.
Is there some function, preferably in javascript, that allows me to check if the link is correct? If it's ok, only "continue linking" to allow the download, and if it's broken, show an alert which says something like "Uh, file is missing, please report this clicking here"
Upvotes: 0
Views: 539
Reputation: 3034
Since JavaScript won't have access to the server's file system, I believe you would need some server-side code. An easy way of accomplishing this is to write a web service that accepts a filename(string). Have it return a boolean. Something like this:
[WebMethod]
public bool CheckFile(string FileName)
{
return File.Exists(FileName);
}
Then, when someone clicks the link, you can call your WebService and write a CallBackFunction which evaluates the returned value. If it's true, you execute the logic you (presumably) already have. If it's false, you can pop a modal informing them that the file no longer exists on the server.
Upvotes: 1