Detecting plugins for pdf
I just found this site that can detect acrobat reader in browser plugins.
Here's the link: http://gemal.dk/browserspy/acrobat.html
Viewing the source code of that page, i found these lines in the script which does the detection of pdf plugin.
<object id="ocx_pdf" classid="clsid:{CA8A9780-280D-11CF-A24D-444553540000}" style="display:none"></object>
<script type="text/javascript"><!--
var i_acrobatreader;
var v_acrobatreader;
var a_acrobatreader;
if (obj(navigator.plugins)) {
for (var i=0; i < navigator.plugins.length; i++) {
if (navigator.plugins[i].name.toLowerCase().indexOf("adobe acrobat") >= 0) {
i_acrobatreader = true;
v_acrobatreader = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("version ") + 8, navigator.plugins[i].description.toLowerCase().lastIndexOf(" for"));
break;
}
}
}
// --></script>
<script type="text/vbscript"><!--
on error resume next
num = 0
myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")
do until num = 6
set tmp = CreateObject(myarray(num))
if IsObject(tmp) then
i_acrobatreader = true
v_acrobatreader = num
end if
num = num + 1
loop
if IsObject(ocx_pdf) and i_acrobatreader then
a_acrobatreader = ocx_pdf.GetVersions
end if
// --></script>
....
<script type="text/javascript"><!--
if (i_acrobatreader) {
document.writeln("Yes");
if (v_acrobatreader) {
document.writeln(" - version " + v_acrobatreader);
}
} else {
document.writeln("No or unable to detect...");
}
// --></script>
....
<script type="text/javascript"><!--
if (i_acrobatreader) {
if (a_acrobatreader) {
var comps = a_acrobatreader.split(",");
for (var i = 0; i < comps.length; i++) {
var detail = comps[i].split("=");
if (detail[0])
document.writeln(detail[0] + " version " + detail[1]+"<br />");
}
} else {
document.writeln("Unable to detect...");
}
} else {
document.writeln("Acrobat Reader not installed.");
}
// --></script>
In my previous applications, by garnering some concepts from other snippets, I came up to this:
<script language="javascript" type="text/javascript">
<!--
/*<![CDATA[*/
var hasAcrobat = navigator.mimeTypes && navigator.mimeTypes["application/pdf"];
/*]]>*/
//-->
</script> <script type="text/vbscript">
<!--
on error resume next
num = 0
myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")
do until num = 6
set tmp = CreateObject(myarray(num))
if IsObject(tmp) then
hasAcrobat = true
v_acrobatreader = num
end if
num = num + 1
loop
// -->
</script> <script language="javascript" type="text/javascript">
<!--
/*<![CDATA[*/
if (! hasAcrobat) {
window.location = '<?=$_SERVER['REQUEST_URI']?>&forceDL';
} else {
window.location = 'some_php_script.php?filesrc=<?=base64_encode($sourceDoc)?>';
}
/*]]>*/
//-->
</script>
Comments