Detectar PDF Reader em msie
-
22-07-2019 - |
Pergunta
Eu uso um IFrame para exibir um documento PDF quando um link dentro desse IFrame é clicado. No entanto, em máquinas sem o leitor, o link irá pedir para download. Existe uma maneira, que o mesmo link pode solicitar que o usuário baixar um leitor quando detecta nenhum leitor em vez disso? Eu pensei que eu já vi isso em algum lugar. Obrigado!
Solução
Isso funciona para mim no 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>
Encontrado-lo aqui. ..mas modificado para remover o " endif "
Outras dicas
Eu sei que esta questão já havia sido respondida, mas recentemente tive de construir uma função que detecta PDF plug-in presença em diferentes navegadores. Isto é o que eu tenho. Esperemos que se ajuda.
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;
}
Aqui estão alguns scripts que ajudam a detectar a presença de Acrobat.
Em JavaScript, você pode fazer algo como:
var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");
e em seguida, pegar um erro de falha ou o valor de retorno de adobePdfObject?