Javascript: Is there a way to find the mime type of the file that a URL points to?
I'm writing a chrome extension to replace links to mp4 files with embedded video, but my method of detecting links to videos (running href through a regex) doesn't work for URLs that redirect to valid files.
You can contact the server to find out the mime type. Use the HEAD
HTTP method to prevent the server from sending the actual content. You can use XMLHttpRequest
to make the HEAD
request from JavaScript.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.