JS Detection browser Adobe Reader plugin

Source: Internet
Author: User

When we want to display PDF documents to users in Web applications, if a user installs a PDF reader such as Adobe Reader, they can open the document directly in the browser,

However, when the user does not install such software, it is naturally not open, for the system or the ease of use of the site, it is best to display the document before the client to detect, if installed

This type of reader directly shows that if not installed, jump to the download page of the reading software such as Adobe Reader or directly to the user, prompting the user to download the installation.

We can detect it first through JavaScript and then make a specified jump based on the test results. If the browser is like Firefox, Google, such as good processing, but IE browser will always encounter

Various problems, through the search for more information and testing finally solved the various versions and different browser problems, the following is the corresponding JavaScript code.

<script type= "Text/javascript" >

Detection browser type: IE, Firefox, Google, Safari

function Getbrowsername () {
var useragent = navigator? Navigator.userAgent.toLowerCase (): "Other";
if (Useragent.indexof ("Chrome") >-1) return "Chrome";
else if (Useragent.indexof ("Safari") >-1) return "Safari";
else if (Useragent.indexof ("MSIE") >-1 | | useragent.indexof ("trident") >-1) return "IE";
else if (Useragent.indexof ("Firefox") >-1) return "Firefox";
return useragent;

return ActiveXObject for IE
function Getactivexobject (name) {
try {
return new ActiveXObject (name);
} catch (e) {

For browsers other than IE
function Getnavigatorplugin (name) {
For (key in Navigator.plugins) {
var plugin = Navigator.plugins[key];
if (plugin.name = = name) return plugin;

//Get Adobe Reader plugin information
Function Getpdfplugin () {
if (getbrowsername () = = ' ie ') {
//load the A Ctivex control
//Acropdf.pdf is used by version 7 and later
//Pdf.pdfctrl are used by version 6 and earlier return Getactivexobject (' acropdf.pdf ') | | Getactivexobject (' Pdf.pdfctrl ');
Else {
return getnavigatorplugin (' Adobe Acrobat ') | | | getnavigatorplugin (' Chrome PDF Viewer ') | | getna Vigatorplugin (' WebKit built-in PDF ');

Determine if the plugin is installed
function isacrobatinstalled () {
Return!! Getpdfplugin ();
function Getacrobatversion () {
try {
var plugin = Getpdfplugin ();
if (getbrowsername () = = ' ie ') {
var versions = plugin. Getversions (). Split (', ');
var latest = Versions[0].split (' = ');
Return parsefloat (latest[1]);
if (plugin.version) return parseint (plugin.version);
return plugin.name;
catch (e) {
return null;

Plugin is installed, jump to the specified page
if (isacrobatinstalled) {
Window.location.href= "";

The reader is not installed, prompting the user to download
Alert ("You may not have a PDF reader installed yet, for the convenience of viewing PDF documents, please download the installation!") ");
Window.location.href= "Http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/chs/AdbeRdr930_zh_CN.exe";

JS Detection browser Adobe Reader plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.