使用标准的 OBJECT 标记,如何显示带有自动提示安装 Java 和后备内容的 Java 小程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4127950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using the standard OBJECT tag, how can I display a java applet with automatic prompts to install Java and with fallback content?
提问by EB.
This is the code i'm currently using: (note - %s is replaced on the server side)
这是我目前使用的代码:(注意 - %s 在服务器端被替换)
<!--[if !IE]>-->
<object
type="application/x-java-applet"
width="300" height="300"
>
<!--<![endif]-->
<!--[if IE]>
<object
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab"
type="application/x-java-applet"
width="300" height="300"
>
<!--><!-- <![endif]-->
<param name="codebase" value="/media/vnc/" >
<param name="archive" value="TightVncViewer.jar" />
<param name="code" value="com.tightvnc.vncviewer.VncViewer" />
<param name="port" value="%s" />
<param name="Open New Window" value="yes" />
</object>
When Java is installed, this works perfectly in both IE and Firefox. When Java is not installed, IE and Firefox both correctly prompt for an autodownload of Java 1.6 from the codebase line. (IE via the activex url given firefox via the Plugin Finder Service)
安装 Java 后,这在 IE 和 Firefox 中都可以完美运行。如果未安装 Java,IE 和 Firefox 都会正确提示从代码库行自动下载 Java 1.6。(IE 通过插件查找器服务提供给 firefox 的 activex url)
Now, suppose I want fallback content to be shown if the plugin isn't installed, say a simple message like "Get Java". From reading the specs, i'd assume this should not change the plugin finding prompt - that is, rendering the fallback should be seen as a failure to render the object tag. Thus, I should still get the plugin finder service prompting me to install Java. Instead, simply adding a single character to the innerHTML of the object element causes Firefox to no longer prompt. Test this by visiting data:text/html,<object type='application/x-java-applet'>Java failed to load</object>
.
现在,假设我希望在未安装插件的情况下显示后备内容,请说一条简单的消息,例如“获取 Java”。从阅读规范来看,我认为这不应该改变插件查找提示——也就是说,呈现回退应该被视为呈现对象标签的失败。因此,我仍然应该得到提示我安装 Java 的插件查找器服务。相反,简单地向对象元素的innerHTML 添加一个字符会导致Firefox 不再提示。通过访问测试这一点data:text/html,<object type='application/x-java-applet'>Java failed to load</object>
。
How can I keep firefox prompting to install Java while providing fallback content?
如何在提供后备内容的同时让 Firefox 提示安装 Java?
URL to test Firefox's Java Plugin Finder Service: data:text/html,<object type='application/x-java-applet'/>
用于测试 Firefox 的 Java Plugin Finder Service 的 URL: data:text/html,<object type='application/x-java-applet'/>
采纳答案by Anon
How can I keep firefox prompting to install Java while providing fallback content?
如何在提供后备内容的同时让 Firefox 提示安装 Java?
Edit/make the VncViewer applet start() method to set a Javascript variable. From Javascript check the variable's existence with setTimeout or setInterval after some seconds. If it fails to appear then java is not working so alert the user to get the latest java runtime from java.com. You could even use the DOM to insert a clickable link.
编辑/制作 VncViewer 小程序的 start() 方法以设置 Javascript 变量。几秒钟后,从 Javascript 中使用 setTimeout 或 setInterval 检查变量是否存在。如果它没有出现,则说明 java 不工作,因此提醒用户从 java.com 获取最新的 java 运行时。您甚至可以使用 DOM 插入可点击的链接。
Should work for any browser and the fallback text will appear. The HTML is simpler too:-
应该适用于任何浏览器,并且会出现后备文本。HTML 也更简单:-
<object type="application/x-java-applet" width="300" height="300">
<param name="codebase" value="/media/vnc/" />
<param name="code" value="com.tightvnc.vncviewer.VncViewer" />
<param name="archive" value="TightVncViewer.jar" />
<param name="mayscript" value="true" />
Java failed to load
</object>
Notes
笔记
classid, as used for IE in the question, finds the highest user installed java version. If the found version is less than 1.6 then the codebase attribute prompts the user to download 1.6. However, if the latest version was 1.7 then security bugfixes could be missed, so wouldn't it be better to prompt for the latest version.
问题中用于 IE 的 classid 查找用户安装的最高 Java 版本。如果找到的版本低于 1.6,则代码库属性会提示用户下载 1.6。但是,如果最新版本是 1.7,则可能会错过安全错误修复,因此提示输入最新版本不是更好吗?
From java plugin 1.5.0_06 (Dec 2005) the highest user installed java version is selected automatically anyway. So the classid used in the question seems somewhat irrelevant in 2011. Whether codebase would work on its own I don't know.
从 java 插件 1.5.0_06(2005 年 12 月)开始,无论如何都会自动选择用户安装的最高 java 版本。所以问题中使用的 classid 在 2011 年似乎有些无关紧要。我不知道代码库是否可以独立工作。
In HTML4 the classid and codebase object attributes are supposed to represent the implementation location (e.g. the applet itself), not the java version. So the IE system looks completely non standard.
在 HTML4 中,classid 和 codebase 对象属性应该代表实现位置(例如小程序本身),而不是 java 版本。所以IE系统看起来完全不标准。
In HTML5 classid and codebase attributes are obsolete.
在 HTML5 中 classid 和 codebase 属性已过时。
The use of "code" attribute or parameter does not appear in HTML4 object spec, nor HTML5.
“代码”属性或参数的使用不会出现在 HTML4 对象规范中,也不会出现在 HTML5 中。
Could not get the HTML4/5 "data" attribute working in IE8 nor FF5.
无法在 IE8 或 FF5 中使用 HTML4/5“数据”属性。
All in all it looks a right mess, and hardly surprising that oracle suggest using the deprecated old applet tag instead of the object tag.
总而言之,它看起来一团糟,而且 oracle 建议使用已弃用的旧小程序标记而不是对象标记也就不足为奇了。
回答by Shahriyar Imanov
Check here: https://eyeasme.com/Shayne/XHTML/appletObject.html
在这里查看:https: //eyeasme.com/Shayne/XHTML/appletObject.html
Question: Why there is only one closing tag? Non-IE browsers will see two opening OBJECT tags [yes, second one won't work because of the unrecognizable value in CLASSID attribute], and they will be accompanied by only one closing counterpart.
问题:为什么只有一个结束标签?非 IE 浏览器将看到两个打开的 OBJECT 标签[是的,第二个将无法工作,因为 CLASSID 属性中的值无法识别],并且它们将只伴随一个关闭的对应物。
EDIT 2: Unfortunately, I couldn't make the method described in that page work on Chrome. All other browsers [FF, IE, Safari and Opera - latest versions] work just fine, except Chrome - it doesn't even load the applet/object.
编辑 2:不幸的是,我无法使该页面中描述的方法在 Chrome 上运行。所有其他浏览器 [FF、IE、Safari 和 Opera - 最新版本] 都可以正常工作,除了 Chrome - 它甚至不加载小程序/对象。
回答by Anon
Seems to me that using [if IE]
classid and codebase attributes complicate the HTML. Also, they are only used to direct the user if Java is not installed. Instead, why not use a setTimeout in JS to call a method in the applet after some seconds, and if it doesn't respond then use JS to advise the user action. That simplifies the object code to something like this:-
在我看来,使用[if IE]
classid 和 codebase 属性会使 HTML 复杂化。此外,它们仅用于在未安装 Java 的情况下指导用户。相反,为什么不使用 JS 中的 setTimeout 在几秒钟后调用小程序中的方法,如果它没有响应,则使用 JS 来建议用户操作。这将目标代码简化为如下所示:-
<p>
<object type="application/x-java-applet"
name="accessName" width="300" height="300">
<param name="codebase" value="/media/vnc/" />
<param name="code" value="com.tightvnc.vncviewer.VncViewer" />
<param name="archive" value="TightVncViewer.jar" />
<param name="scriptable" value="true" />
<param name="mayscript" value="true" />
<param name="port" value="%s" />
<param name="Open New Window" value="yes" />
</object>
</p>
If the applet has to call JS, the mayscript param is needed for Java plugins before 1.6.0.10. The scriptable param is still required according to javadocs 1.6.0.21 if JS needs to call the applet. However, in one of my tests with 1.6.0.24 for a signed applet, IE8 called it OK from JS without scriptable being set true. For the above applet, you don't need "mayscript", or the author would have included it, but you might need "scriptable" for any setTimeout call.
如果小程序需要调用JS,1.6.0.10之前的Java插件需要mayscript参数。如果 JS 需要调用小程序,根据 javadocs 1.6.0.21 仍然需要可脚本化的参数。但是,在我使用 1.6.0.24 对已签名小程序进行的一项测试中,IE8 从 JS 调用它可以,而无需将 scriptable 设置为 true。对于上面的小程序,您不需要“mayscript”,否则作者会包含它,但是对于任何 setTimeout 调用,您可能需要“scriptable”。