From the Firefox developer website, I know that Firefox uses
objectURL = window.URL.createObjectURL(file);
to get url of file type, but in chrome and other webkit browsers we have window.webkitURL.createObjectURL()
for detecting url.
I don't know how to swap this functions based on browser engines, and I need it to be worked on both browsers (Chrome and firefox)
https://developer.mozilla.org/en/DOM/window.URL.createObjectURL
createObjectURL() The URL. createObjectURL() static method creates a string containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.
The URL. createObjectURL() method has been removed from the MediaStream interface. This method has been deprecated in 2013 and superseded by assigning streams to HTMLMediaElement.
createObjectURL is a static method provided by the URL Web API. Returns a DOMString containing a unique blob URL, that is a URL with blob: as its scheme, followed by an opaque string uniquely identifying the object in the browser.
You could define a wrapper function:
function createObjectURL ( file ) {
if ( window.webkitURL ) {
return window.webkitURL.createObjectURL( file );
} else if ( window.URL && window.URL.createObjectURL ) {
return window.URL.createObjectURL( file );
} else {
return null;
}
}
And then:
// works cross-browser
var url = createObjectURL( file );
Simple one liner:
var createObjectURL = (window.URL || window.webkitURL || {}).createObjectURL || function(){};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With