Detecting a Safari InfoCard PlugIn Using JavaScript

A few weeks ago Pete Rowley pointed out an issue with Opinity's InfoCard support. It would appear that the folks at Opinity decided to refuse InfoCard tokens from non-IE7 selectors. So, for instance, if I attempt to log in using the Safari-based selector, I get the following alert:

While I can understand that the webmaster at Opinity might be trying to help out users who are attempting to use a non-Microsoft browser, a more appropriate way to do this would be to ask the browser itself, via some simple JavaScript, if it understands embedded objects of type "application/x-informationcard".

So, for those of you out there that are running a relying party that understands InfoCard/Cardspace, and you want to limit access to that particular login medium to browsers that understand the protocol, here is a small snippet of JavaScript that will query a browser's installed plug-ins and check for InfoCard support:

 <script language="JavaScript">
 var infoCardMimeType="application/x-informationcard"; //InfoCard MIME Type

 function isInfoCardSupportedByPlugIn() {
    if (navigator.plugins && navigator.plugins.length > 0) {
	   var pluginsArrayLength = navigator.plugins.length;
	   // for each plugin...
	   for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	       // check to see if plugin has assoc. MIME type and 
	       // if so, if it is of type "application/x-informationcard"
	       if (navigator.plugins[pluginsArrayCounter][0] 
	            && infoCardMimeType == navigator.plugins[pluginsArrayCounter][0].type) {
	           return true;
	   return false;

Using the above code, here's what we are able to discern about the browser with which you are currently using to view this page:

So, hopefully the Opinity people will take the time to let us choose the credential types that we would prefer to log in with, without forcing us to make unnecessary choices about browsers and operationg systems.