如何知道,如果浏览器具有PDF查看器或不? [英] How to know if browser has PDF viewer or not?

查看:239
本文介绍了如何知道,如果浏览器具有PDF查看器或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看PDF到iframe中。它工作正常。但是,一些客户端不能够看到它在IE中。他们把它作为下载选项。



我怎么能确定是否有浏览器的PDF查看器或没有,并提示用户,他有没有PDF浏览器?



请注意:我使用asp.net mvc的5(C#)



我试过的这个,但不帮助我。我的一些客户端的问题有的Adobe PDF,所以下面的回答没有问题。但是,这些谁拥有nitropdf或Chrome PDF查看器,下面的答案不帮我。我想idenitify所有的PDF阅读器。否则,如果客户有某种PDF阅读器,那么警报也将显示,没有PDF阅读器已安装。这就是错误的事情。



我从عبدالنورالتومي的答案和它的工作对浏览器和Mozilla。 下面是我修改中的JS。



但<强> IE仍然没有对此作出回应。我不知道如何在IE浏览器检查它具有PDF查看器或没有。
。对于IE浏览器,我越来越虽然有PDF查看器下面的错误有:




解决方案

我试着以下通过采取帮助解决方案< A HREF =http://stackoverflow.com/a/24056048/3330969>عبدالنورالتومي,它在浏览器和Mozilla



<帮助任何PDF阅读器pre> VAR getAcrobatInfo =函数(){

VAR getBrowserName =函数(){
返回this.name = this.name ||函数(){
变种的userAgent =导航仪? navigator.userAgent.toLowerCase():其他;

如果(userAgent.indexOf(铬)GT; -1){回归铬 }
,否则如果(userAgent.indexOf(野生动物园)-1个){返回野生动物园 }
,否则如果(userAgent.indexOf(MSIE)-1个|| userAgent.indexOf(三叉戟)-1个){返回,即; }
,否则如果(userAgent.indexOf(火狐)> -1){返回火狐;}
返回的userAgent;
}();
};

VAR getActiveXObject =功能(名称){
尝试{返回新的ActiveXObject(名); }赶上(E){}
};

VAR getNavigatorPlugin =功能(名称){
尝试{
为(以navigator.plugins键){
VAR插件= navigator.plugins [关键]
如果(plugin.name.toLowerCase()的indexOf(名称)方式> -1){返回插件; }
}
}赶上(E){

}

};

VAR getPDFPlugin =函数(){
返回this.plugin = this.plugin ||函数(){
如果(getBrowserName()==',即'){
返回getActiveXObject('AcroPDF.PDF')|| getActiveXObject('PDF.PdfCtrl');
}
,否则{
返回getNavigatorPlugin('的Adobe Acrobat')|| getNavigatorPlugin('PDF')|| getNavigatorPlugin('福昕阅读器'); //适用于有字,如使用Adobe Acrobat,PDF和福昕阅读器的所有插件。
}
}();
};

VAR isAcrobatInstalled =函数(){
返回!! getPDFPlugin();
};

VAR getAcrobatVersion =函数(){
尝试{
VAR插件= getPDFPlugin();

如果(getBrowserName()=='即'){
变种版本= plugin.GetVersions()分割(,)。
VAR最新版本= [0] .split('=');
返回parseFloat(最新[1]);
}

如果(plugin.version)返回parseInt函数(plugin.version);
返回plugin.name

}
赶上(E){
返回NULL;
}
};

返回{
浏览器:getBrowserName()//返回浏览器名称
杂技演员:isAcrobatInstalled()?真:假的,//返回PDF查看器或不启用
acrobatVersion:getAcrobatVersion()// reurn为浏览器


杂技演员版本};
}

和我有以下错误的IE浏览器,虽然我已经安装了PDF阅读器我浏览器:



然后我解决它通过此链接



然后,添加新的条件为IE 11 三叉戟,现在它工作正常。此外,我增加选项来检查福昕阅读器。您可以在或病症还添加其他pdf阅读器的名称。


I am viewing PDF into iframe. It works fine. But some of the client don't able to see it in IE. They get it as download option.

How can I identify if browser has pdf viewer or not and prompt user that he hasn't pdf viewer?

Note: I am using asp.net mvc 5 (c#).

I tried this, but don't help me. The problem with me some of the client has Adobe PDF, so no issue for below answer. But those who have nitropdf or chrome pdf viewer, below answer don't help me. I want to idenitify all pdf viewer. otherwise if client has some kind of pdf viewer then also alert will be display that no pdf viewer is installed. And that's wrong thing.

I applied this code by getting help from عبد النور التومي's answer and it worked for chrome and mozilla. Here is the js I modified.

But IE still not respond to it. I don't know how to check in IE that it has pdf viewer or not. For IE, I'm getting following error though there is pdf viewer is there:

解决方案

I tried following solution by taken help from عبد النور التومي, which helps for any pdf viewer in chrome and mozilla

    var getAcrobatInfo = function () {

        var getBrowserName = function () {
            return this.name = this.name || function () {
                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;
            }();
        };

        var getActiveXObject = function (name) {
            try { return new ActiveXObject(name); } catch (e) { }
        };

        var getNavigatorPlugin = function (name) {
            try {
                for (key in navigator.plugins) {
                    var plugin = navigator.plugins[key];
                    if (plugin.name.toLowerCase().indexOf(name) > -1) { return plugin; }
                }
            } catch (e) {

            }

        };

        var getPDFPlugin = function () {
            return this.plugin = this.plugin || function () {
                if (getBrowserName() == 'ie') {
                    return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
                }
                else {
                    return getNavigatorPlugin('adobe acrobat') || getNavigatorPlugin('pdf') || getNavigatorPlugin('foxit reader');  // works for all plugins which has word like 'adobe acrobat', 'pdf' and 'foxit reader'.
                }
            }();
        };

        var isAcrobatInstalled = function () {
            return !!getPDFPlugin();
        };

        var getAcrobatVersion = function () {
            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;
            }
        };

        return {
            browser: getBrowserName(),      // Return browser name
            acrobat: isAcrobatInstalled() ? true : false,   // return pdf viewer is enabled or not
            acrobatVersion: getAcrobatVersion()  // reurn acrobat version for browser


   };
}

And I got following error for IE, Though I have pdf viewer installed in my browser.:

Then I solved it by this link.

Then I add new condition for IE 11 trident and now it works fine. Also I added option to check for foxit reader. you can add another pdf reader name also in or condition.

这篇关于如何知道,如果浏览器具有PDF查看器或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆