Is there a way to check if the user has installed a PDF reader? Maybe with a ActiveX component?
Could you please help me?
No, I don't think so - but you could always direct your links through Google's PDF reader by default - which will work for everyone.
http://docs.google.com/viewer
Please be aware that this will channel your PDF files through Google's servers, so you will lose an element of security.
This was very useful for me:
Java script - Adobe plug-in detector
From comments area, get the corrections for Safari Browser too.
You can detect installed plugins with window.navigator.plugins
This will return an array with details of installed plugins, but this will not work for Internet Explorer. When running this code, IE only returns an array with embed tags in the page. Thanks IE, so useful?
Ok, let's try to work this out. The following function should work in all major browsers expect IE.
function hasPlugin(name) {
name = name.toLowerCase();
var plugins = window.navigator.plugins;
for (var i=0, len = plugins.length; i < len; i++) {
if (plugins[i].name.toLowerCase().indexOf(name) > -1) {
return true;
}
}
return false;
}
you can call this function and check the plugin status like this
hasPlugin('Flash');
hasPlugin('QuickTime');
For IE, we should try this
function hasPlugin(name) {
try {
new ActiveXObject(name);
return true;
} catch (e) {
return false;
}
}
you can call this function and check the plugin status for IE
hasPlugin('ShockwaveFlash.ShockwaveFlash');
You can made this function declaration cross browser like this
var hasPlugin;
if (navigator.userAgent.indexOf('MSIE')) {
hasPlugin = function(name) {
try {
new ActiveXObject(name);
return true;
} catch (e) {
return false;
}
}
}
else {
hasPlugin = function(name) {
name = name.toLowerCase();
var plugins = window.navigator.plugins;
for (var i=0, len = plugins.length; i < len; i++) {
if (plugins[i].name.toLowerCase().indexOf(name) > -1) {
return true;
}
}
return false;
}
}
Then you can call the function in a cross browser way. I am sorry, I don't installed any PDF plugin for my browsers, -Firefox, Chrome or IE- so I could tell you exact name the argument we should pass hasPlugin function.
I hope, this will help you. By the way, I did not tried the code in browsers, this is a therocial knowledge on me. But I guess this will help you -hope- :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With