Check whether a url file path is viewable or downloadable in javascript/jQuery

Viewed 48

I have example file paths on a web page like:

www.example.com/uploads/abc.pdf
www.example.com/uploads/abc.json
www.example.com/uploads/abc.txt
www.example.com/uploads/abc.avi

The file type can be anything. Some files are easily viewable in a browser like txt or image files but some file types start downloading when opened in a browser.

How can I know whether the URL file path is viewable in div or downloadable only? Is there any way to decide from the MIME type or anything we can check with Javascript/jQuery if that file is viewable in a div or downloadable only before viewing/downloading starts?

Any help would be appreciated.

1 Answers
Related