How to choose between `window.URL.createObjectURL()` and `window.webkitURL.createObjectURL()` based on browser?

JavascriptWeb DevelopmentFront End Scripts

To choose, you need to define a wrapper function −

function display ( file ) {
   if ( window.webkitURL ) {
      return window.webkitURL.createObjectURL( file );
   } else if ( window.URL && window.URL.createObjectURL ) {
      return window.URL.display( file );
   } else {
   return null;
   }
}

After that set it for cross-browser −

var url = display( file );
raja
Published on 06-Apr-2018 11:46:01
Advertisements