JavaScript can be used to determine what version of PDF your browser supports using various methods. I believe that JavaScript can only determine the major version of an installed Acrobat Reader plugin, and not the minor version.
For Internet Explorer you can check if the ActiveXObject exists for different versions of Acrobat Reader. The ActiveXObject name for version 7.0 and 8.0 is "AcroPDF.PDF.1", for other versions it is found by the ActiveXObject name "PDF.PDFCtrl." concatenated with a version number. The only exception is version 4.0, and you can review the code below for an explanation.
For FireFox and other browsers you can find the plugin named "Adobe Acrobat" which will contain a description of the plugin and its version. The description for version 8.0 is "Adobe PDF Plug-In For Firefox and Netscape" while other versions contain the version number.
The following three functions will help in determining the version of PDF the client browser supports. I have left out cross-browser support as that is a problem that has already been solved in multiple ways.
| /** * Determines version of the Acrobat Reader plugin for FireFox and Netscape * @returns the major version of the plugin and returns null if PDF is not supported **/ function OtherPDFVersion() { var version = null; var plugin = navigator.plugins["Adobe Acrobat"]; if (plugin == null) return null; if (plugin.description == "Adobe PDF Plug-In For Firefox and Netscape") { version = '8.0'; } else { version = plugin.description.split('Version ')[1] + '.0'; } return version; } /** * Determines version of the Acrobat Reader plugin for InternetExplorer * @returns the major version of the plugin and returns null if PDF is not supported **/ function IEPDFVersion() { var version = null; if (hasActiveXObject('AcroPDF.PDF.1')) { version = '7.0'; } if (hasActiveXObject('PDF.PdfCtrl.1')) { version = '4.0'; } for (var i=2; i<10; i++) { if (hasActiveXObject('PDF.PdfCtrl.' + i)) { version = i + '.0'; } } return version; } /** * Helper method to determine if IE contains an ActiveXObject with a given name * @param name - the name of an ActiveXObject * @returns true if the browser contains the ActiveXObject **/ function hasActiveXObject(name) { var has = false; try { activeXObject = new ActiveXObject(name); if (activeXObject != null) { has = true; } } catch (e) { has = false; } return has; } |
2 comments:
can you please help me if there is a way to detect plugin for adobe reader 9?
Dear Sir,
I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site www.codegain.com and it is basically aimed .net resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter.
Looking forward to hearing from you and hope you will join with us soon.
Thank you
RRaveen
Founder CodeGain.com
Post a Comment