Created
March 4, 2015 21:58
-
-
Save ItalyPaleAle/778b2f541ba570bc05b0 to your computer and use it in GitHub Desktop.
Detect PDF Viewer plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
hasPDFViewer.js | |
Version: 1.0.0 | |
Date: 2015-03-04 | |
(C) 2015 Alessandro Segala | |
License: BSD-2-Clause (http://opensource.org/licenses/BSD-2-Clause) | |
Original author: Ben Kitzelman (http://thecodeabode.blogspot.ca/2011/01/detect-adobe-reader-plugin.html) | |
*/ | |
function hasPDFViewer() { | |
var hasActiveXObject = function(name) { | |
try { | |
var obj = new ActiveXObject(name) | |
if(obj) { | |
return true | |
} | |
} | |
catch(e) {} | |
return false | |
} | |
var hasNavigatorPlugin = function(name) { | |
for(key in navigator.plugins) { | |
var plugin = navigator.plugins[key] | |
if(plugin.name == name) { | |
return true | |
} | |
} | |
return false | |
} | |
// Does not match IE11+, but IE11+ supports navigator.plugins | |
var userAgent = navigator ? navigator.userAgent.toLowerCase() : 'other' | |
if(~(userAgent.indexOf('msie'))) { | |
// Load the activeX control | |
// AcroPDF.PDF is used by version 7 and later | |
// PDF.PdfCtrl is used by version 6 and earlier | |
return hasActiveXObject('AcroPDF.PDF') | |
|| hasActiveXObject('PDF.PdfCtrl') | |
} | |
else { | |
return hasNavigatorPlugin('Adobe Acrobat') | |
|| hasNavigatorPlugin('Chrome PDF Viewer') | |
|| hasNavigatorPlugin('WebKit built-in PDF') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from: https://gist.github.com/benkitzelman/6d4ead05b3d4b80518f3