JavaScript DHTML/Development/PlugIn — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 10:02, 26 мая 2010

Accessing a Plug-In

<HTML>
<HEAD>
<TITLE>Accessing Installed Plug-ins</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function playVideo() {
 window.document.yourWav.play()
}
function stopVideo() {
 window.document.yourWav.stop()
}
function rewindVideo() {
 window.document.yourWav.rewind()
}
function forwardVideo() {
 window.document.yourWav.forward()
}
function forward() {
 window.document.yourWav.frameBack()
}
function back() {
 window.document.yourWav.frameForward()
}
// --></SCRIPT>
</HEAD>
<BODY>
<H1>A video of the planet yourWav</H1>
<SCRIPT LANGUAGE="JavaScript"><!--
plugins=navigator.plugins
if(plugins["NPAVI32 Dynamic Link Library"]){
 document.write("<EMBED SRC="yourWav.avi" NAME="yourWav" ")
 document.writeln("AUTOSTART="TRUE" WIDTH="350" HEIGHT="240">")
}else{
 document.write("Sorry. Your browser does not have ")
 document.writeln("LiveVideo installed.")
}
// --></SCRIPT>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Start" onClick="rewindVideo()">
<INPUT TYPE="BUTTON" VALUE="Play" onClick="playVideo()">
<INPUT TYPE="BUTTON" VALUE="Frame Forward" onClick="forward()">
<INPUT TYPE="BUTTON" VALUE="Frame Backward" onClick="back()">
<INPUT TYPE="BUTTON" VALUE="Stop" onClick="stopVideo()">
<INPUT TYPE="BUTTON" VALUE="End" onClick="forwardVideo()">
</FORM>
</BODY>
</HTML>



Determining Whether the LiveVideo Plug-In Is Installed

<HTML>
<HEAD>
<TITLE>Detecting Installed Plug-ins</TITLE>
</HEAD>
<BODY>
<H1>A video of the planet yourWav</H1>
<SCRIPT LANGUAGE="JavaScript"><!--
plugins = navigator.plugins;
if(plugins["NPAVI32 Dynamic Link Library"]){
 document.write("<EMBED SRC="yourFile.avi" AUTOSTART="TRUE"")
 document.writeln("WIDTH="350" HEIGHT="270">")
}else{
 document.write("Sorry. Your browser does not have ")
 document.writeln("LiveVideo installed.")
}
// --></SCRIPT>
</BODY>
</HTML>



Displaying a List of Navigator Plug-Ins

<html>
<head>
  <script type="text/javascript">
  <!--
    function showWindow(){
      var len = navigator.plugins.length;
      newWin = window.open("", "", "height=400,width=500");
      newWin.document.write("<p>Plug-In Info:</p>");   
      for(var i = 0; i < len; i++){
        newWin.document.write("<li>" + navigator.plugins[i].description + "</li>");
      }
   
      newWin.document.close()
    }
  //-->
  </script>
</head>
<body>
  <form>
    <input type="button" value="Show Plug-In Information" onclick="showWindow()">
  </form>
</body>
</html>



Displaying Plug-In Information

<HTML>
<HEAD>
<TITLE>Determining Installed Plug-ins</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript"><!--
p = navigator.plugins;
for(var i=0;i<p.length;++i){
 with(document){
  writeln("<P><B>Plugin: </B>"+p[i].name+"</P>")
  writeln("<P><B>File name: </B>"+p[i].filename+"</P>")
  writeln("<P><B>Description: </B>"+p[i].description+"</P>")
  writeln("<P><B>MIME Types: </B>")
  for(var j=0;j<p[i].length;++j)
   writeln(p[i][j].type+"</BR>")
  writeln("</P><HR>")
 }
}
// --></SCRIPT>
</BODY>
</HTML>



Display PDF using plugin

<html>
<head>
<script language="JavaScript">
<!--
function findPlugin(ext) {
  var thisExt, findExt;
  for (var n=0; n < navigator.plugins.length; n++) {
      for (var m=0; m < navigator.plugins[n].length; m++) {
          thisExt = navigator.plugins[n][m].description.toLowerCase();
          findExt = thisExt.substring(0, thisExt.indexOf(" "));
          if (findExt == ext)
             return(true);
      }
  }
  return(false);
}
  
if (findPlugin("pdf")) {
   document.open();
   document.write("<embed src="yourFile.pdf" width="100%">");
   document.close();
}
else {
   location = "http//www.wbex.ru";
}
//-->
</script>
</head>
</html>



Find pluin for Midi

<html>
<head>
<script language="JavaScript">
<!--
var extNeed, namePlug;
function findPlugin(ext) {
  var thisExt, findExt;
  extNeed = ext;
  for (var n=0; n < navigator.plugins.length; n++) {
      for (var m=0; m < navigator.plugins[n].length; m++) {
          thisExt = navigator.plugins[n][m].description.toLowerCase();
          findExt = thisExt.substring(0, thisExt.indexOf(" "));
          if (findExt == ext) {
             namePlug = navigator.plugins[n].name;
             return(true);
          }
      }
  }
  return(false);
}
if (findPlugin("midi")) {
   alert("A plug-in for " + namePlug +" is installed.");
}else {
   alert("A plug-in application to play ." + extNeed + " files is not installed!");
}
//-->
</script>
</head>
</html>



JavaScript to enumerate and display all installed plug-ins

<HTML>
<HEAD>
<TITLE>About Plug-ins</TITLE>
</HEAD>
<BODY>
<SCRIPT language="javascript">
numPlugins = navigator.plugins.length;
if (numPlugins > 0)
  document.writeln("Installed plug-ins");
else
 document.writeln("No plug-ins are installed.");
for (i = 0; i < numPlugins; i++) {
 plugin = navigator.plugins[i];
 document.write("<center><font size=+1><b>");
 document.write(plugin.name);
 document.writeln("</b></font></center><br>");
 document.writeln("<dl>");
 document.writeln("<dd>File name:");
 document.write(plugin.filename);
 document.write("<dd><br>");
 document.write(plugin.description);
 document.writeln("</dl>");
 document.writeln("<p>");
 document.writeln("<table border=1 >");
 document.writeln("<tr>");
 document.writeln("<th width=20%>Mime Type</th>");
 document.writeln("<th width=50%>Description</th>");
 document.writeln("<th width=20%>Suffixes</th>");
 document.writeln("<th>Enabled</th>");
 document.writeln("</tr>");
 numTypes = plugin.length;
 for (j = 0; j < numTypes; j++)
 {
  mimetype = plugin[j];
 
  if (mimetype){
   enabled = "No";
   enabledPlugin = mimetype.enabledPlugin;
   if (enabledPlugin && (enabledPlugin.name == plugin.name))
    enabled = "Yes";
   document.writeln("<tr align=center>");
   document.writeln("<td>");
   document.write(mimetype.type);
   document.writeln("</td>");
   document.writeln("<td>");
   document.write(mimetype.description);
   document.writeln("</td>");
   document.writeln("<td>");
   document.write(mimetype.suffixes);
   document.writeln("</td>");
   document.writeln("<td>");
   document.writeln(enabled);
   document.writeln("</td>");
   document.writeln("</tr>");
  }
 }
 document.write("</table>");
}
</SCRIPT>
</BODY>
</HTML>



Listing Plug-In Properties

<HTML>
<HEAD>
<TITLE>Listing the properties of a plug-in</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function listProperties(obj) {
 document.writeln("<B>Properties of: </B>"+obj+"<BR>")
 for(var p in obj)
  document.writeln(p+"<BR>")
}
// --></SCRIPT>
</HEAD>
<BODY>
<EMBED SRC="yourfile.avi"><BR>
<SCRIPT LANGUAGE="JavaScript"><!--
listProperties(document.embeds[0])
// --></SCRIPT>
</BODY>
</HTML>



Properties of the Plugin Object

  Property         Description
  description   Contains the description of the plug-in.
  filename      Contains the filename of a plug-in program.
  length        Contains the number of MIME types supported by the plug-in.
  name          Contains the name of the plug-in.



Scan through each plug-in by provided parameters

<html>
<head>
<script language="JavaScript">
<!--
document.write("There are <b>" + navigator.plugins.length + "</b> plug-ins installed.<p>");
document.write("<table border=1 width="100%" cellpadding=5>" +
               "<tr>" +
               "<td>Name</td>" +
               "<td>Description</td>" +
               "<td>Filename</td>" +
               "<td>Suffixes / MIME " + "type</td>" +
               "</tr>");
for (n=0; n < navigator.plugins.length; n++) {
    document.write("<tr valign="top">" +
                   "<td>" + navigator.plugins[n].name + "</td>" +
                   "<td>" + navigator.plugins[n].description + "</td>" +
                   "<td>" + navigator.plugins[n].filename +"</td><td>");
    for (m=0; m < navigator.plugins[n].length; m++) {
        document.write(navigator.plugins[n][m].suffixes + " = " + navigator.plugins[n][m].type +
                       "<br>");
    }
    document.write("</td></tr>");
}
document.write("</table>");
//-->
</script>
</head>
</html>



Synchronizing Two Plug-Ins

<HTML>
<HEAD>
<TITLE>Synchronizing Plug-ins</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function play() {
 window.document.embeds[0].play()
 window.document.embeds[1].play()
}
function stop() {
 window.document.embeds[0].stop()
 window.document.embeds[1].pause()
}
function start() {
 window.document.embeds[0].rewind()
 window.document.embeds[1].stop()
}
function end() {
 window.document.embeds[0].forward()
 window.document.embeds[1].stop()
}
// --></SCRIPT>
</HEAD>
<BODY onLoad="start()">
<H1>The Planet yourWav</H1>
<EMBED SRC="yourfile.avi" NAME="video" AUTOSTART="TRUE"
 WIDTH="350" HEIGHT="240">
<EMBED SRC="yourfile.wav" HIDDEN="TRUE">
<FORM>
<INPUT TYPE="BUTTON" VALUE="Start" onClick="start()">
<INPUT TYPE="BUTTON" VALUE="Play" onClick="play()">
<INPUT TYPE="BUTTON" VALUE="Pause" onClick="stop()">
<INPUT TYPE="BUTTON" VALUE=" End " onClick="end()">
</FORM>
</BODY>
</HTML>