JavaScript 導(dǎo)航對(duì)象包含的子對(duì)象稱(chēng)為插件。這個(gè)對(duì)象是一個(gè)數(shù)組,每個(gè)插件會(huì)在瀏覽器上安裝一個(gè)條目。導(dǎo)航器和插件對(duì)象只被網(wǎng)景,F(xiàn)irefox 和 Mozilla 支持。
下面是一個(gè)示例,列出了所有安裝瀏覽器上的插件:
<html>
<head>
<title>List of Plug-Ins</title>
</head>
<body>
<table border="1">
<tr>
<th>Plug-in Name</th>
<th>Filename</th>
<th>Description</th>
</tr>
<script language="JavaScript" type="text/javascript">
for (i=0; i<navigator.plugins.length; i++) {
document.write("<tr><td>");
document.write(navigator.plugins[i].name);
document.write("</td><td>");
document.write(navigator.plugins[i].filename);
document.write("</td><td>");
document.write(navigator.plugins[i].description);
document.write("</td></tr>");
}
</script>
</table>
</body>
</html>
每個(gè)插件在數(shù)組中都有一個(gè)入口。每個(gè)入口有以下屬性:
您可以使用這些屬性在腳本中找到已安裝的插件,然后使用 JavaScript可以適當(dāng)運(yùn)行的多媒體文件如下:
<html>
<head>
<title>Using Plug-Ins</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
media = navigator.mimeTypes["video/quicktime"];
if (media){
document.write("<embed src='quick.mov' height=100 width=100>");
}
else{
document.write("<img src='quick.gif' height=100 width=100>");
}
</script>
</body>
</html>
注意:我們使用 HTML <embed> 標(biāo)記中嵌入一個(gè)多媒體文件。
讓我們舉一個(gè)真實(shí)的例子,它在幾乎所有的瀏覽器里面都有效:
<html>
<head>
<title>Using Embeded Object</title>
<script type="text/javascript">
<!--
function play()
{
document.demo.Play();
}
}
function stop()
{
if (document.demo.IsPlaying()){
document.demo.StopPlay();
}
}
function rewind()
{
if (document.demo.IsPlaying()){
document.demo.StopPlay();
}
document.demo.Rewind();
}
//-->
</script>
</head>
<body>
<embed id="demo" name="demo"
src="/attachments/image/wk/wkjavascript/kumite.swf"
width="318" height="300" play="false" loop="false"
pluginspage="http://www.macromedia.com/go/getflashplayer"
swliveconnect="true">
</embed>
<form name="form" id="form" action="#" method="get">
<input type="button" value="Start" onclick="play();" />
<input type="button" value="Stop" onclick="stop();" />
<input type="button" value="Rewind" onclick="rewind();" />
</form>
</body>
</html>
更多建議: