判断客户端浏览器是否安装了java,是否可以启动小程序 [英] Determine whether client browser has java installed and can launch applets

查看:31
本文介绍了判断客户端浏览器是否安装了java,是否可以启动小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 .aspx 页面,它将在用户单击按钮后最终启动一个小程序(我正在使用 标记).因此,我想检测用户浏览器上是否启用/安装了 java.

I am developing an .aspx page which will ultimately launch an applet after the user clicks on a button (I am using the <applet> tag). So, I would like to detect if java is enabled/installed on the user's browser.

我正在使用 navigator.javaEnabled() 方法.然而,即使这在 IE7 上运行良好,它在 Firefox 3.0.12 上返回不一致的结果(不知道不同的浏览器),有时说启用了 java(它是),然后在启动小程序和再次从applet 返回到这个页面,就会报错.如果我关闭 firefox 并返回小程序启动页面,navigator.javaEnabled() 将再次(正确)报告 true.

I am using navigator.javaEnabled() method. However, even though this is working fine on IE7, it is returning inconsistent results on Firefox 3.0.12 (don't know about different browsers), sometimes saying that java is enabled (which it is), and then after launching the applet and coming back out of the applet to this page again, it will report false. If I close firefox and return to the applet launching page, navigator.javaEnabled() will report true again (correctly).

是否有什么决定了这种不一致的行为,或者 navigator.javaEnabled() 不是进行 Java 小程序检查的最佳方法?

Is there anything that is determining this inconsistent behaviour or is navigator.javaEnabled() not the best way to do the java applet check?

提前致谢.

推荐答案

在你的小程序中制作一个方法

Make in your applet a method

public boolean isRunning() { return true; }

现在创建一个小程序:

<applet src=".../yourapplet.jar" id="someId">

现在将这段代码包装在一些辅助函数中

And now wrap this code in some helper function

try {
  var x = document.getElementById('someId').isRunning()
  return x;
} catch(e) {
  return false;
}

为什么会这样?如果小程序运行,它将返回 true.如果小程序没有运行或 Java 不受支持,你会得到一个异常,所以你会得到错误.

Why this works? If applet runs it will return true. If applet doesn't run or Java is not supported you'll get an exception, so you'll get false.

这篇关于判断客户端浏览器是否安装了java,是否可以启动小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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