Domanda

Uso un IFrame per visualizzare un documento Pdf quando si fa clic su un collegamento all'interno di tale IFrame. Tuttavia, su macchine senza lettore, il collegamento richiederà il download. Esiste un modo in cui lo stesso link può richiedere all'utente di scaricare un lettore quando non rileva invece alcun lettore? Pensavo di averlo visto da qualche parte. Grazie!

È stato utile?

Soluzione

Questo funziona per 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>

L'ho trovato qui. ..modificato per rimuovere il " ; endif "

Altri suggerimenti

So che a questa domanda era già stata data una risposta, ma di recente ho dovuto creare una funzione che rilevi la presenza del plug-in PDF su diversi browser. Questo è quello che ho ottenuto. Eventualmente se aiuta.

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;
}

Ecco alcuni script che aiutano a rilevare la presenza di Acrobat.

In JavaScript, puoi fare qualcosa del tipo:

var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");

e quindi rilevare un errore o il valore restituito di adobePdfObject?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top