PDA

View Full Version : cross-browser plug-in detect


boggly
01-06-2003, 05:44 AM
I'm completely stumped by this one. What I want to do is detect if a viewer has a certain plug-in (Acrobat in this case) and send them to an appropriate page if they do. Unlike most of the times I've scripted, this is easy with Netscape but hard with Internet Explorer. So far this is what I have:

<script language="VBscript" type="text/vbscript">
<!--

Function IEPluginDetect(pluginname)
on error resume next
IEPluginDetect = False
IEPluginDetect = IsObject(CreateObject(pluginname))
If (err) then
IEPluginDetect = False
End If
End Function

// -->
</script>

<script language="JavaScript" type="text/javascript">
<!--

function NSPluginCheck(label)
{
can = false;
plug = label;
if (navigator.mimeTypes && navigator.mimeTypes.length)
{
x = navigator.mimeTypes[plug];
if (x && x.enabledPlugin)
{
can = true;
}
}
return can;
}


// load new URL depending on browser capability

function sendTo(loc)
{
NSDetect = NSPluginCheck('application/pdf');
if (NSDetect && loc != null)
{
var NewUrl = "new/path/" + loc + ".pdf";
window.location.href = NewUrl;
return false;
}
else
{
return true;
}
}

// -->
</script>

This is what the links that call the function would be like:

<a href="/dir/someURL.html" onclick="return sendTo('newname');" >text link</a>

This works with NS, but not IE. IE gives an "Expected end of statement" error, NS displays nothing. I haven't been able to figure out how to change the location with IE because I don't know VBScript. Any help or ideas would be greatly appreciated, because this sure is aggravating!

--boggly

glenngv
01-06-2003, 05:52 AM
CreateObject needs a valid class id.
Sample class id for pdf is PDF.PdfCtrl.5

I have downloaded a plugin detector script somewhere.
Here it is...

boggly
01-06-2003, 07:26 AM
Okay, I'll see if I can get it to work, but IE is acting really strange on my system. Thanks though.

--boggly