Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try with jQuery:

jQuery.get(url, function (response, status, xhr) {
  if (xhr.getResponseHeader("content-type").indexOf("text") > -1)
    // url content is of type : text
  else
    // url has downloadable content
});

For more intel, refer to : https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!