Dave's Brain

Browse - Programming Tips - Which suffixes/extensions does this web browser support?

Date: 2010nov11
Language: javaScript
Platform: web
Warning: This is a a bit old fashioned.  Now use the <video> and <audio> tags

Q.  Which suffixes/extensions does this web browser support?
eg is .SWF or .WAV handled?

A.  This doesn't work in IE.  Use the navigator.plugins member.

// Returns an array of all suffixes supported by the enabled plugins function getPluginSuffixes() { var numPlugins, plugin, mimetype, enabled, sufs, suffix; var i, j, k; var result = new Array(); for (i = 0; i < navigator.plugins.length; i++) { plugin = navigator.plugins[i]; for (j = 0; j < plugin.length; j++) { mimetype = plugin[j]; if (mimetype == null) continue; enabled = false; enabledPlugin = mimetype.enabledPlugin; if (enabledPlugin && (enabledPlugin.name == plugin.name)) { enabled = true; } if (!enabled) continue; if (mimetype.suffixes == null) continue; sufs = mimetype.suffixes.split(/,/); for (k = 0; k < sufs.length; k++) { suffix = sufs[k]; if (suffix == '') continue; result.push(suffix.toLowerCase()); } } } return result; } // Is a given suffix supported? function isPluginSuffix(target_suf) { var sufs = getPluginSuffixes(); if (sufs.length == 0) return true; // Assume yes for IE :( target_suf= target_suf.toLowerCase(); for (var i = 0; i < sufs.length; i++) { if (target_suf == sufs[i]) return true; } return false; }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.