Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top