JavaScript DHTML/HTML/Mime Type

Материал из Web эксперт
Версия от 07:23, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Properties of the Mimetype Object

/*
+-------------------------+--------------------------------------+
Property                   Description
+-------------------------+--------------------------------------+
description                Contains the description of Mimetype.
+-------------------------+--------------------------------------+
enabledPlugin              Contains the plug-in for a specific Mimetype.
+-------------------------+--------------------------------------+
suffixes                   Contains the file extension for Mimetype.
+-------------------------+--------------------------------------+
type                       Contains the string representation of Mimetype.
+-------------------------+--------------------------------------+
*/



Show Browser Mime type (Firefox)

<html>
<head>
<script language="JavaScript">
<!--
   var htmlString= "MIME types <form><select size=25>";
   function showTypes() {
      for (var i=0; i < navigator.mimeTypes.length; i++)
          htmlString += "<option>" + navigator.mimeTypes[i].type;
      htmlString += "</select></form>";
      document.write(htmlString);
   }
//-->
</script>
</head>
<body onLoad="showTypes()">
</body>
</html>



Using the mimeTypes Object

<HTML>
<HEAD>
<TITLE>Determining how MIME types are handled</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript"><!--
m = navigator.mimeTypes;
for(var i=0;i<m.length;++i){
 with(document){
  writeln("<P><B>MIME type: </B>"+m[i].type+"</P>")
  writeln("<P><B>Description: </B>"+m[i].description+"</P>")
  writeln("<P><B>Suffixes: </B>"+m[i].suffixes+"</P>")
  writeln("<HR>")
 }
}
// --></SCRIPT>
</BODY>
</HTML>



Verifying a MIME Type

<HTML>
<HEAD>
<TITLE>W3C DOM Event Propagation</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function mimeIsReady(mime_type) {
    if (navigator.mimeTypes[mime_type]) {
        if (navigator.mimeTypes[mime_type].enabledPlugin) {
            return true
        }
    }
    return false
}
</SCRIPT>
</HEAD>
<BODY >
</BODY>
</HTML>



Verifying Plug-in and MIME Type

<HTML>
<HEAD>
<TITLE>W3C DOM Event Propagation</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function mimeAndPluginReady(mime_type, plug_in) {
    if (mimeIsReady(mime_type)) {
        var plugInOfRecord = navigator.mimeTypes[mime_type].enabledPlugin
        plug_in = plug_in.toLowerCase()
        for (var i = 0; i < navigator.plugins.length; i++) {
            if (navigator.plugins[i].name.toLowerCase().indexOf(plug_in) != -1) {
                if (navigator.plugins[i] == plugInOfRecord) {
                    return true;
                }
            }
        }
    }
    return false;
}
</SCRIPT>
</HEAD>
<body>
</BODY>
</HTML>