JS判断浏览器是否支持acrobat reader

var adobeReaderInfo = {
	installed: false,
	version: "0.0",
	goRedirect: false,
	getAdobeReader: function() {
		// 如果是Firefox浏览器
		if (navigator.plugins && navigator.plugins.length) {
			for (var x = 0; x < navigator.plugins.length; x++) {
				if (navigator.plugins[x].description.indexOf("Adobe Acrobat") != -1) {
					adobeReaderInfo.version = parseFloat(navigator.plugins[x].description
						.split("Version ")[1]);
					if (adobeReaderInfo.version.toString().length == 1)
						adobeReaderInfo.version += ".0";
					adobeReaderInfo.installed = true;
					break;
				} else if (navigator.plugins[x].description
					.indexOf("Adobe PDF Plug-In") != -1) {
					adobeReaderInfo.installed = true;
					adobeReaderInfo.version = "8+";
					break;
				}
			}
			// 下面代码都是处理IE浏览器的情况
		} else if (window.ActiveXObject) {
			for (var _x = 2; _x < 10; _x++) {
				try {
					oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + _x + "');");
					if (oAcro) {
						adobeReaderInfo.installed = true;
						adobeReaderInfo.version = _x + ".0";
					}
				} catch (e) {}
			}
			try {
				oAcro4 = new ActiveXObject("PDF.PdfCtrl.1");
				if (oAcro4) {
					adobeReaderInfo.installed = true;
					adobeReaderInfo.version = '4.0';
				}
			} catch (e) {}

			try {
				oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
				if (oAcro7) {
					adobeReaderInfo.installed = true;
					adobeReaderInfo.version = '7.0';
				}
			} catch (e) {}
		}
	},
	judgeAdobe: function() {
		if (adobeReaderInfo.installed) {
			if (parseInt(adobeReaderInfo.version, 10) < 7) {
				if (confirm("Adobe Reader 版本太低可能会引起打印的文件布局错位,是否更新到最新版本?")) {
					adobeReaderInfo.goRedirect = false;
					window.open("http://get.adobe.com/cn/reader/", "", "");
					return false;
				} else {
					adobeReaderInfo.goRedirect = true;
				}
			} else {
				adobeReaderInfo.goRedirect = true;
			}
		} else {
			if (confirm("请先安装Adobe Reader")) {
				window.open("http://get.adobe.com/cn/reader/", "", "");
				return false;
			}
		}
	}
};

 

你可能感兴趣的:(reader)