想知道使用者瀏覽器裡裝了哪些外掛(Flash Player、PDF 閱讀器、各類媒體播放器等),可以直接走訪 navigator.plugins 這個集合。它上面的每一項都提供了名稱、檔名、描述與內含的 MIME 類型數量。
下面的程式把結果動態輸出成一個表格:
document.writeln("<TABLE BORDER=1><TR VALIGN=TOP>",
"<TH ALIGN=left>i",
"<TH ALIGN=left>名稱",
"<TH ALIGN=left>文件名",
"<TH ALIGN=left>描述",
"<TH ALIGN=left>類型數</TR>");
for (i = 0; i < navigator.plugins.length; i++) {
document.writeln("<TR VALIGN=TOP><TD>", i,
"<TD>", navigator.plugins[i].name,
"<TD>", navigator.plugins[i].filename,
"<TD>", navigator.plugins[i].description,
"<TD>", navigator.plugins[i].length,
"</TR>");
}
document.writeln("</TABLE>");
這段程式適合用來做「能力偵測」的前置排查,但不要只依賴插件清單來判斷功能可用性。更穩健的方式是直接做特性偵測(例如檢查 navigator.mimeTypes 或嘗試建立對應物件),並為偵測失敗的情況準備替代方案。另外,IE 上的 navigator.plugins 行為與標準瀏覽器有差異,需要另外處理。