取得瀏覽器安裝的所有插件
有時需要判斷瀏覽器安裝那些第三方插件,比如:VLC、Flash Player、PDF Viewer等等,藉以作後續的動作,比如說沒有Flash Player引導user安裝,下面這程式就非常有用:
navigator.plugins
會返回一個已安裝plugin的數組
<!doctype html> <html> <body> <div id="example"></div> <script type="text/javascript"> var x=navigator.plugins.length; // store the total no of plugin stored var txt="Total plugin installed: "+x+"<br/>"; txt+="Available plugins are->"+"<br/>"; for(var i=0;i<x;i++) { txt+=navigator.plugins[i].name + "<br/>"; } document.getElementById("example").innerHTML=txt; </script> </body> </html>
輸出:
Total plugin installed: 4 Available plugins are-> Widevine Content Decryption Module Native Client Chrome PDF Viewer
參考:
取得某一Plugin版本:
<scrip> function getFlashVersion() { var flash = navigator.plugins.namedItem('Shockwave Flash'); if (typeof flash != 'object') { // flash is not present return undefined; } if(flash.version){ return flash.version; } else { //No version property (e.g. in Chrome) return flash.description.replace(/Shockwave Flash /,""); } } </script>
參考:
[……]