Use File name extension to MIME type - Javascript String Operation

Javascript examples for String Operation:String URL

Description

Use File name extension to MIME type

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//www.j  a  va2  s.c  o  m
Object.prototype.gif = 'gotcha';
(function() {
    var extToMimes = {
        'img': 'image/jpeg',
        'png': 'image/png'
    }
    window.getMimeByExt = function(ext) {
        return extToMimes[ext];
    }
})();
document.body.innerHTML = getMimeByExt('gif');
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials