浏览器Java插件检测

浏览器Java插件检测,java,javascript,browser,plugins,cross-browser,Java,Javascript,Browser,Plugins,Cross Browser,确定浏览器中是否安装了Sun Java插件的首选方法是什么? 脚本src=”http://java.com/js/deployJava.js" if(deployJava.versionCheck('1.6')) { 警报(“1.6已安装”) } 这不是对您的确切问题的回答,而是作为确定浏览器本身的解决方案提供的。不要太苛刻,这是我不久前写的非常旧的代码 import java.applet.*; public class BrowserDetector extends Applet {

确定浏览器中是否安装了Sun Java插件的首选方法是什么?

脚本src=”http://java.com/js/deployJava.js" if(deployJava.versionCheck('1.6')) { 警报(“1.6已安装”) }
这不是对您的确切问题的回答,而是作为确定浏览器本身的解决方案提供的。不要太苛刻,这是我不久前写的非常旧的代码

import java.applet.*;

public class BrowserDetector extends Applet {

    public void init() {
        if (isNetscape()) {
            System.out.println("This browser is a Netscape Browser.");
        }
        if (isMicrosoft()) {
            System.out.println("This browser is a Microsoft Browser.");
        }
        System.out.println("VM Type: " + getVMType());
    }

    public static boolean isNetscape() {
        try {
            Class.forName("netscape.applet.MozillaAppletContext");
        } catch (ClassNotFoundException e) {
            System.out.println("This browser is not a Netscape Browser.");
            return false;
        }
        return true;
    }

    public static boolean isMicrosoft() {
        try {
            Class.forName("com.ms.applet.GenericAppletContext");
        } catch (ClassNotFoundException e) {
            System.out.println("This browser is not a Microsoft Browser.");
            return false;
        }
        return true;
    }

    public String getVMType() {
        String theBrowser = "No VM";
        String appletContext = getAppletContext().toString();
        if (appletContext.startsWith("sun.applet.AppletViewer"))
            theBrowser = "APPLETVIEWER";
        else if (appletContext.startsWith("netscape.applet."))
            theBrowser = "NETSCAPE";
        else if (appletContext.startsWith("com.ms.applet."))
            theBrowser = "MICROSOFT";
        else if (appletContext.startsWith("sunw.hotjava.tags.TagAppletPanel"))
            theBrowser = "HOTJAVA";
        else if (appletContext.startsWith( "sun.plugin.navig.win32.AppletPlugin"))
            theBrowser = "NETSCAPEPLUGIN";
        else if (appletContext.startsWith( "sun.plugin.ocx.ActiveXApplet"))
            theBrowser = "MICROSOFTPLUGIN";
        else if (appletContext.startsWith( "sun.plugin.viewer.context.IExplorerAppletContext"))
            theBrowser = "MICROSOFTPLUGINJRE1.4";

        return theBrowser;
    }

}

<>你也可以考虑脚本。

这不总是有效的。(1) 如果它在firefox中被禁用,则表示未安装。(2) 在lion os x上,即使在所有浏览器中都禁用了它,它也会告诉installedunsigned小程序
import java.applet.*;

public class BrowserDetector extends Applet {

    public void init() {
        if (isNetscape()) {
            System.out.println("This browser is a Netscape Browser.");
        }
        if (isMicrosoft()) {
            System.out.println("This browser is a Microsoft Browser.");
        }
        System.out.println("VM Type: " + getVMType());
    }

    public static boolean isNetscape() {
        try {
            Class.forName("netscape.applet.MozillaAppletContext");
        } catch (ClassNotFoundException e) {
            System.out.println("This browser is not a Netscape Browser.");
            return false;
        }
        return true;
    }

    public static boolean isMicrosoft() {
        try {
            Class.forName("com.ms.applet.GenericAppletContext");
        } catch (ClassNotFoundException e) {
            System.out.println("This browser is not a Microsoft Browser.");
            return false;
        }
        return true;
    }

    public String getVMType() {
        String theBrowser = "No VM";
        String appletContext = getAppletContext().toString();
        if (appletContext.startsWith("sun.applet.AppletViewer"))
            theBrowser = "APPLETVIEWER";
        else if (appletContext.startsWith("netscape.applet."))
            theBrowser = "NETSCAPE";
        else if (appletContext.startsWith("com.ms.applet."))
            theBrowser = "MICROSOFT";
        else if (appletContext.startsWith("sunw.hotjava.tags.TagAppletPanel"))
            theBrowser = "HOTJAVA";
        else if (appletContext.startsWith( "sun.plugin.navig.win32.AppletPlugin"))
            theBrowser = "NETSCAPEPLUGIN";
        else if (appletContext.startsWith( "sun.plugin.ocx.ActiveXApplet"))
            theBrowser = "MICROSOFTPLUGIN";
        else if (appletContext.startsWith( "sun.plugin.viewer.context.IExplorerAppletContext"))
            theBrowser = "MICROSOFTPLUGINJRE1.4";

        return theBrowser;
    }

}