Pergunta

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.

Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top