简体   繁体   English

在DOM上加载Java applet

[英]loading java applet on DOM load

I searched for it a lot but probably I am searching wrong strings. 我进行了很多搜索,但可能是搜索错误的字符串。 A Java applet is feeding live bits into my pages, java applet accesses the input fields on my page and places the information 一个Java applet正在向页面中添加实时位,java applet访问页面上的输入字段并放置信息

<input type="hidden" id="F1" value="Nothing Yet">

and then it calls a javascript functionon the page say LivePicker() and then it simply picks up a value 然后在页面上调用LivePicker()上的javascript函数,然后简单地获取一个值

var ClockVal = document.getElementById("F1").value;
document.getElementById("ICSCLOCK").innerHTML = ClockVal;

The problem I am facing is, this works fine but sometimes in firebug console it give errors like LivePicker is not defined, while LivePicker would be working perfectly fine on the page while sometimes it will give F1 is not defined, while my clock would be working fine. 我面临的问题是,它可以正常工作,但有时在firebug控制台中会给出未定义LivePicker的错误,而LivePicker在页面上会运行得很好,而有时它将给出F1却未定义,而我的时钟仍在工作精细。 All of these errors appear at page load. 所有这些错误都会在页面加载时出现。

Java applet places the data sequentially, it first place the data and then calls the js function to process it. Java applet按顺序放置数据,它首先放置数据,然后调用js函数进行处理。 That works perfectly fine on test pages with minimum HTML and JS but when I integrate it to my application, which uses a lot of components from YUI and a lot of my own JS code (which is now minified obviously), it give these errors. 在使用最少的HTML和JS的测试页上,这可以很好地工作,但是当我将其集成到应用程序中时,该应用程序使用了YUI的许多组件和我自己的JS代码(现在已经明显减少了),它会出现这些错误。 One thing I would like to add, before minification, these errors were a lot likely but after minification of JS and CSS, the page load time is reduced to half and the appearence of these errors are reduced to half as well. 我想补充一点,在缩小之前,这些错误很有可能出现,但是在缩小JS和CSS之后,页面加载时间减少到一半,而这些错误的出现也减少到一半。

I am suspecting this is due to, on page load, applet tries to manipulate the DOM which is not ready yet. 我怀疑这是由于在页面加载时,applet试图操纵尚未准备好的DOM。 Is there anything, which could stop the applet to wait until the DOM is fully loaded? 是否有什么可能会使applet停止等待DOM完全加载? I tried window.onload and onDOMReady function of YUI, they seem to make no effect at all. 我尝试了YUI的window.onload和onDOMReady函数,它们似乎根本没有效果。

Can any one help please? 有人可以帮忙吗?

you could try using setTimeout to delay execution 您可以尝试使用setTimeout延迟执行

https://developer.mozilla.org/en/DOM/window.setTimeout https://developer.mozilla.org/en/DOM/window.setTimeout

or the jQuery library could also help out with the ready event on the document object 或jQuery库也可以帮助解决文档对象上的ready事件

http://docs.jquery.com/Events/ready#fn http://docs.jquery.com/Events/ready#fn

The browser should delay executing the window.onload code until after the DOM tree is created and after all other external resources are fully loaded and the page is displayed in the browser. 浏览器应该延迟执行window.onload代码,直到创建DOM树之后以及所有其他外部资源都完全加载并且页面在浏览器中显示为止。

The window.onload should work. window.onload应该工作。 Your applet must be running before the onload event. 小程序必须在onload事件之前运行。

As a test, can you do the following and see if it changes anything: 作为测试,您可以执行以下操作并查看它是否有任何更改:

  • create a hidden "set" field in the page with value "false"; 在页面中创建一个隐藏的“设置”字段,其值为“ false”;
  • on window.onload set the value for the "set" field to "true"; 在window.onload上,将“设置”字段的值设置为“ true”;
  • in your applet check the "set" field; 在您的小程序中,检查“设置”字段;
  • only start doing things in your applet if the "set" field is defined and has a value of "true"; 仅在定义了“设置”字段且值为“ true”的情况下,才开始在applet中执行操作;

One other thing, don't do a busy waiting in your applet to test for the "set" field. 另一方面,不要在小程序中忙于测试“设置”字段。 Your applet should take no action if the field is undefined or false. 如果该字段未定义或为false,则您的小程序不应采取任何措施。 You can reactivate it on window.onload if needed. 您可以根据需要在window.onload上重新激活它。

This problem was resolved using dpb suggestions in slightly different way. 使用dpb建议以稍微不同的方式解决了此问题。 This blog post I wrote should explain every bit to those who are facing similar problem. 我写的这篇博客文章应该向面临类似问题的人们进行详尽的解释。

Controlling Java applet from Javascript especially if you make round-trips to the web page from applet 从Javascript控制Java小程序,尤其是当您从小程序往返访问网页时

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

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