Pdf Reading Detection in MsIE

I use an IFrame to view a Pdf document when a link is clicked in that IFrame. However, on machines without a reader, the link will prompt you to download. Is there a way that the same link can encourage the user to load the reader when it does not detect the reader? I thought I saw it somewhere. Thanks!

+3
source share
4 answers

This works for me in IE:

<script>
var p;
try {
p = new ActiveXObject('AcroExch.Document');
}
catch (e) {
// active x object could not be created
document.write('doesnt look like the PDF plugin is installed...');
}
if (p) {
    document.write('does look like the pdf plugin is installed!');
}
</script>

Found here. .. but modified to remove "endif"

+5
source

Here are a few scenarios that help detect the presence of Acrobat.

+3
source

I know that this question has already been answered, but I recently had to create a function that detects the presence of a plug-in in different browsers. This is what I got. Hope this helps.

function hasPdfPlugin() {   
//detect in mimeTypes array
if (navigator.mimeTypes != null && navigator.mimeTypes.length > 0) {        
    for (i = 0; i < navigator.mimeTypes.length; i++) {
        var mtype = navigator.mimeTypes[i];
        if(mtype.type == "application/pdf" && mtype.enabledPlugin)
            return true;
    }
}

//detect in plugins array
if (navigator.plugins != null && navigator.plugins.length > 0) {
    for (i = 0; i < navigator.plugins.length; i++) {
        var plugin = navigator.plugins[i];
        if (plugin.name.indexOf("Adobe Acrobat") > -1
                || plugin.name.indexOf("Adobe Reader") > -1) {
            return true;
        }

    }
} 
// detect IE plugin
if (window.ActiveXObject) {
    // check for presence of newer object       
    try {
        var oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
        if (oAcro7) {
            return true;
        }
    } catch (e) {
    }

    // iterate through version and attempt to create object 
    for (x = 1; x < 10; x++) {
        try {
            var oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');");
            if (oAcro) {
                return true;
            }
        } catch (e) {
        }
    }

    // check if you can create a generic acrobat document
    try {
        var p = new ActiveXObject('AcroExch.Document');
        if (p) {
            return true;
        }
    } catch (e) {
    }

}

// Can't detect in all other cases
return false;
}
+3
source

In JavaScript, you can do something like:

var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");

and then either catch the failure error or return adobePdfObject?

+1
source

Source: https://habr.com/ru/post/1714273/


All Articles