簡體   English   中英

瀏覽器Java插件檢測

[英]Browser Java Plugin Detection

確定瀏覽器中是否安裝了 Sun Java 插件的首選方法是什么?

java 部署工具包


script src="http://java.com/js/deployJava.js"

if (deployJava.versionCheck('1.6'))
{ 
alert("1.6 installed")
} 

您也可以考慮PluginDetect腳本。

這不是您確切問題的答案,而是作為確定瀏覽器本身的解決方案提供的。 不要太苛刻,這真的是我前段時間寫的老代碼。

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;
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM