如果用户尚未安装 JRE,我该如何提示用户安装 JRE?
我正在编写一个 Java 小程序,想知道将其包含在网页中的最佳方法。
我希望它能够提示用户安装 JRE(如果尚未安装)。 这个功能(理想情况下)应该可以在运行 Java 的任何操作系统上跨浏览器工作。 另一个要求是小程序不应在页面加载时加载,而应在用户操作之后加载,而不是在每次页面加载时加载 JVM。 我猜这是官方的SUN方式,但它使用document.write()
,所以页面渲染完成后我无法使用它。
I am writing a Java applet, and would like to know the best way to include it in a web page.
I'd like it to prompt the user to install JRE if she hasn't it already.
This feature should (ideally) work cross-browser on any OS Java runs on.
Another requirement is that the applet should not be loaded on page load, but after a user action, not to load the JVM on every page load.
I guess this is the official SUN way, but it uses document.write()
, so I can't use it after the page has finished rendering.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议只使用小程序标签。 正如 Alex B 所评论的,如果用户没有 JRE,大多数浏览器都会提示用户安装。
即使 Sun 也建议 使用 applet 标记(Intranet 除外) 除非您位于 Intranet 上。 我想这里的逻辑是,您可以在内部服务器上托管 JRE 下载,并使用嵌入和 JRE 下载。 对象标签将下载定向到该服务器。
我曾经使用 embed & 对象标签,但由于版本号,这最终会成为一个麻烦。 假设您需要 Java 1.5。 所以你在对象中指定了 & 嵌入标签以确保用户在没有 1.5 的情况下必须升级。 然而,这并不是您真正想要的,您希望它将它们升级到最新的 JVM。 无论如何,当我上次玩它时,这并不是最聪明的行为——他们现在可能已经改进了。
I would recommend just using the applet tag. As Alex B comments, most browsers will prompt the user to install at that point if they don't have the JRE.
Even Sun recommends using the applet tag except on Intranets unless you are on an intranet. I imagine the logic here is that you can host the JRE download on an internal server, and use the embed & object tags to direct the download to that server.
I used to use the embed & object tags, but that ends up being a hassle due to the version numbers. Lets say you require Java 1.5. So you specify that in the object & embed tags to make sure the user will have to upgrade if they don't have 1.5. However, that's not really what you want, you want it to upgrade them to the very latest JVM. In any event, it was not the smartest behavior when I last played with it-- it's possible they have improved it now.
我同意jwls,最好使用applet标签,因为使用嵌入和对象很难正确跨浏览器 - 以至于每个浏览器都需要自定义设置越来越有必要了。
但是,使用 applet 标记时,您需要提防 Microsoft VM 1.1 上的用户。 当我在二月份进行测试时,它们仍然占 5% 的 Java 版本。 如果这些用户访问需要更高版本的页面,他们将看到可怕的灰色区域。
解决方案(在 java.net 上讨论之后)是使用一个小小程序来检查 Java 版本,如果不满足目标版本,则重定向到失败页面。 这是我的来源:
JavaRedirectorApplet.java
示例 HTML
I agree with jwls, it is better to use an applet tag because using embed and object are very awkward to get right cross browser - to the point where a custom setup per browser is getting necessary.
However using the applet tag you need to beware of users on Microsoft's VM 1.1. When I tested in February they still accounted for 5% of Java versions. If these users visit a page where a later version is required they will see a horrible grey area.
The solution for this (after discussion on java.net) was to use a small applet which checks the Java version and redirects to a failure page if the target version isn't met. Here is my source:
JavaRedirectorApplet.java
Example HTML