Navigator.mimetypes Structure
I'm curious about how it is working this structure. When I'm accesing the navigator.mimetypes from Javascript I'm accesing an object. >>> typeof(navigator.mimeTypes) 'obje
Solution 1:
navigator.mimeTypes
returns an object called MimeTypeArray
it's not a traditional JavaScript array but an object that had Array like properties, you can access it's properties either by index or name.
edit: When you use navigator.mimeTypes['someType']
you're treating the MimeTypeArray
like a hash map, that has someType
mapped to a MimeType
object in the array that also has a type
property of the same value as the key. This is a strange object in the DOM (not technically JavaScript) and you don't typically see many objects like this.
Solution 2:
functionGetMimeTypes() {
var message = "";
// Internet Explorer supports the mimeTypes collection, but it is always emptyif (navigator.mimeTypes && navigator.mimeTypes.length > 0) {
var mimes = navigator.mimeTypes;
for (var i=0; i < mimes.length; i++) {
message += "<b>" + mimes[i].type + "</b> : " + mimes[i].description + "<br />";
}
}
else {
message = "Your browser does not support this example!";
}
var info = document.getElementById ("login_info");
info.innerHTML = message;
}
GetMimeTypes();
Post a Comment for "Navigator.mimetypes Structure"