Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webbrowser, detect if there is a PDF reader installed?

Is there a way to check if the user has installed a PDF reader? Maybe with a ActiveX component?

Could you please help me?

like image 299
Ruutert Avatar asked Apr 12 '11 19:04

Ruutert


Video Answer


3 Answers

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.

like image 22
Steve Mayne Avatar answered Dec 08 '22 12:12

Steve Mayne


This was very useful for me:

Java script - Adobe plug-in detector

From comments area, get the corrections for Safari Browser too.

like image 24
Morcilla de Arroz Avatar answered Dec 08 '22 10:12

Morcilla de Arroz


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- :-)

like image 94
Fatih Acet Avatar answered Dec 08 '22 10:12

Fatih Acet