Как определить установленную на клиенте среду выполнения Java с веб-сайта ASP .NET? - PullRequest
3 голосов
/ 29 января 2009

У меня есть веб-сайт ASP .NET, на котором размещен апплет Java. Java-апплет требует версии 1.6 Обновление 11 среды выполнения Java.

Как я могу определить, что на клиенте установлена ​​соответствующая среда выполнения, чтобы я мог отображать информативное сообщение, если это не так?

Спасибо

Карл.

РЕДАКТИРОВАТЬ: Решение должно быть независимым от платформы.

Ответы [ 12 ]

0 голосов
/ 09 февраля 2009

Скопируйте и вставьте в адресную строку браузера, чтобы проверить:

JavaScript: предупреждение (navigator.javaEnabled ())

Работает в Mozilla (FF3) и IE7. (64)

0 голосов
/ 09 февраля 2009

Может быть, этот скрипт поможет. Это только для Windows.

<script language='javascript' type='text/javascript'>
var javaVersion;
var shell;
try 
{
    // Create WSH(WindowsScriptHost) shell, available on Windows only
    shell = new ActiveXObject("WScript.Shell");

    if (shell != null) 
    {
        // Read JRE version from Window Registry
        try 
        {
            javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\");
        } 
        catch(e) 
        {
            // handle exceptions raised by 'shell.regRead(...)' here
            // so that the outer try-catch block would receive only
            // exceptions raised by 'shell = new ActiveXObject(...)'
            alert('error reading registry');
        }
    } 
} 
catch(e) 
{
    // Creating ActiveX controls thru script is disabled 
    // in InternetExplorer security options 

    // To enable it: 
    // a. Go to the 'Tools --> Internet Options' menu
    // b. Select the 'Security' tab
    // c. Select zone (Internet/Intranet)
    // d. Click the 'Custom Level..' button which will display the
    // 'Security Settings' window.
    // e. Enable the option 'Initialize and script ActiveX controls
    // not marked as safe'

    activeXDisabled = true;
} 

// Check whether we got required (1.6) Java Plugin
if ( javaVersion != null && javaVersion.indexOf("1.6")) 
{
    pluginDetected = true;
    alert('it is installed!')
}

if (pluginDetected) 
{
    // show applet page
} 
else if (confirm("Java Plugin 1.6 not found")) 
{
    // show install page
    alert('not found')
} 
else 
{
    // show error page
    alet('error')
}
</script>
...