简体   繁体   English

如果Java applet无法运行,则执行JavaScript

[英]Executing JavaScript in the event Java applet fails to run

I have a web page with an embedded Java applet that connects to a server on my LAN for the purpose of measuring LAN Speed. 我有一个带有嵌入式Java小程序的网页,该网页连接到LAN上的服务器,目的是测量LAN速度。 The reason I am using a Java applet is because as far as I am aware, Javascript is too inaccurate to use for measuring LAN Speed. 我之所以使用Java小程序,是因为据我所知,Javascript太不准确,无法用于测量LAN速度。

However, I do have an (inaccurate) javascript version that can do a really rough LAN Speed measurement. 但是,我确实有一个(不准确的)JavaScript版本,该版本可以进行非常粗略的LAN Speed测量。

How can I tell if the applet successfully ran, and if not, to execute the javascript fallback speed test? 如何判断小程序是否成功运行,如果执行失败,则执行javascript后备速度测试? I'm using Java 8 and Google Chrome 36. 我正在使用Java 8和Google Chrome 36。

Here's what I've tried: 这是我尝试过的:

<applet id="SpeedTester" code="SpeedTester.class" archive="SpeedTester.jar"> 
    <param...>
    <param...>
    <param...>
    <script>alert("Applet Failed to Execute!"); runJSSpeedTest();</script>
</applet>

However, it seems as though the code in <script> always runs regardless of if Java is installed, disabled, or enabled. 但是,似乎<script>的代码始终运行,无论是否安装,禁用或启用Java。

The applet should provide a method to confirm it loaded OK. 小程序应提供一种方法来确认它已加载确定。 A JS should poll the applet for a time, trying each time to access that method with an 'OK' result. JS应该轮询小程序一段时间,每次尝试以“ OK”结果访问该方法。 It the JS has not received an 'OK' after a certain time limit, use the JS speed test. 如果在一定时间限制后JS仍未收到“ OK”,请使用JS速度测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM