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

查看:137
本文介绍了确定客户端浏览器是否安装了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是启用(这是),然后运行该小程序后再回来了小程序的这一页,它会报告错误。如果我关闭Firefox,并返回到小程序启动页面,navigator.javaEnabled()将再次报告真(正确)。

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?

先谢谢了。

推荐答案

在你的applet制作方法

Make in your applet a method

public boolean isRunning() { return true; }

现在创建一个小程序:

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

而现在把这个包code在一些辅助功能

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天全站免登陆