在 DOM 加载时加载 java applet

发布于 2024-08-18 08:27:41 字数 822 浏览 6 评论 0原文

我搜索了很多,但可能我搜索的是错误的字符串。 Java 小程序将实时位输入到我的页面中,Java 小程序访问我页面上的输入字段并放置信息

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

,然后它调用页面上的 javascript 函数,例如 LivePicker(),然后它只是获取一个值

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

我面临的问题是的,这工作正常,但有时在 firebug 控制台中它会给出诸如 LivePicker 未定义之类的错误,而 LivePicker 在页面上工作得很好,有时它会给出 F1 未定义,而我的时钟工作正常。所有这些错误都会在页面加载时出现。

Java小程序是顺序放置数据的,它先放置数据,然后调用js函数进行处理。这在具有最少 HTML 和 JS 的测试页面上工作得很好,但是当我将它集成到我的应用程序中时,它使用了 YUI 中的许多组件和我自己的 JS 代码(现在显然已缩小),它会给出这些错误。我想补充的一件事是,在缩小之前,这些错误很可能发生,但是在缩小 JS 和 CSS 之后,页面加载时间减少了一半,这些错误的出现也减少了一半。

我怀疑这是由于在页面加载时,小程序尝试操作尚未准备好的 DOM。有什么东西可以阻止小程序等待 DOM 完全加载吗?我尝试了YUI的window.onload和onDOMReady函数,它们似乎根本没有效果。

有人可以帮忙吗?

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

<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

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. 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. 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. 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.

I am suspecting this is due to, on page load, applet tries to manipulate the DOM which is not ready yet. Is there anything, which could stop the applet to wait until the DOM is fully loaded? I tried window.onload and onDOMReady function of YUI, they seem to make no effect at all.

Can any one help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡写薰衣草的香 2024-08-25 08:27:41

您可以尝试使用 setTimeout 来延迟执行

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

或 jQuery 库也可以帮助处理文档对象上的就绪事件

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

you could try using setTimeout to delay execution

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

or the jQuery library could also help out with the ready event on the document object

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

那些过往 2024-08-25 08:27:41

浏览器应该延迟执行 window.onload 代码,直到之后
DOM 树被创建,并且在所有其他外部资源完全加载并且页面显示在浏览器中之后。

window.onload 应该可以工作。您的小程序必须在 onload 事件之前运行。

作为测试,您可以执行以下操作并查看它是否会更改任何内容:

  • 在页面中创建一个值为“false”的隐藏“set”字段;
  • 在 window.onload 上将“set”字段的值设置为“true”;
  • 在您的小程序中检查“设置”字段;
  • 仅当定义了“set”字段且值为“true”时才开始在小程序中执行操作;

另一件事是,不要在小程序中忙于等待来测试“set”字段。如果该字段未定义或为 false,您的小程序不应采取任何操作。如果需要,您可以在 window.onload 上重新激活它。

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.

The window.onload should work. Your applet must be running before the onload event.

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";
  • on window.onload set the value for the "set" field to "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";

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. You can reactivate it on window.onload if needed.

懒猫 2024-08-25 08:27:41

这个问题是使用 dpb 建议以稍微不同的方式解决的。我写的这篇博文应该向那些面临类似问题的人解释一切。

从 Javascript 控制 Java 小程序,特别是当您从小程序到网页进行往返时

This problem was resolved using dpb suggestions in slightly different way. 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文