MSIE에서 PDF 리더를 감지하십시오
-
22-07-2019 - |
문제
Iframe 내의 링크가 클릭 될 때 iframe을 사용하여 PDF 문서를보십시오. 그러나 독자가없는 기계에서는 링크가 다운로드하라는 메시지가 표시됩니다. 동일한 링크가 독자가 독자를 대신 감지 할 때 독자를 다운로드하도록 프롬프트 할 수있는 방법이 있습니까? 나는 이것을 어딘가에 보았다고 생각했다. 감사!
해결책
이것은 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>
여기에서 찾았습니다. .. 그러나 "endif"를 제거하도록 수정되었습니다.
다른 팁
이 질문이 이미 답변되었음을 알고 있지만 최근에는 다른 브라우저에서 PDF 플러그인 존재를 감지하는 기능을 구축해야했습니다. 이것이 내가 얻은 것입니다. 도움이되기를 바랍니다.
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;
}
다음은 몇 가지 스크립트입니다 그것은 Acrobat의 존재를 감지하는 데 도움이됩니다.
JavaScript에서는 다음과 같은 작업을 수행 할 수 있습니다.
var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");
그런 다음 실패 오류 또는 adobepdfobject의 반환 값을 포착합니까?
제휴하지 않습니다 StackOverflow