当“onload”发生时我如何得到通知脚本已完成

发布于 2024-08-28 19:19:21 字数 152 浏览 10 评论 0原文

当 html 页面加载时我收到通知

-> onStateChange, stateFlags: STATE_IS_NETWORK + STATE_STOP

但当页面加载并且 onload 脚本完成运行时我需要通知。

有什么提示吗? 谢谢

I get a notification when a html page is loaded

-> onStateChange, stateFlags: STATE_IS_NETWORK + STATE_STOP

but I need a notification when the page ist loaded and a onload script has finished running.

Any hints ?
THX

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

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

发布评论

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

评论(2

难以启齿的温柔 2024-09-04 19:19:21

也许您可以添加第二个侦听器来“加载”事件。我无法找到任何文档来确认事件侦听器是按设置顺序调用的,但下面代码的一些实验表明情况似乎如此。如果存在竞争条件,我希望有时会看到“AB”,有时会看到“BA”:

<input type="text" id="field"/>

<script>

    var t = document.getElementById("field");
    t.value="";

    function a(e) {
        t.value = t.value + "A";
    }

    function b(e) {
        t.value = t.value + "B";
    }

    window.addEventListener("load", a, false);
    window.addEventListener("load", b, false);

</script>

需要注意的一件事是,如果您太晚添加第二个事件侦听器(即加载事件已经触发),它将不会称为。

不管怎样,感觉像是一个黑客,但只是一个想法,以防你找不到更好的方法来处理它。

Maybe you could add a second listener to "load" events. I was not able to find any documentation confirming that events listeners are called in order they are set, but some experiments with the code below shows that it seems to be the case. If there was a race condition I would expect to see sometimes "AB" and sometimes "BA":

<input type="text" id="field"/>

<script>

    var t = document.getElementById("field");
    t.value="";

    function a(e) {
        t.value = t.value + "A";
    }

    function b(e) {
        t.value = t.value + "B";
    }

    window.addEventListener("load", a, false);
    window.addEventListener("load", b, false);

</script>

One thing to be careful with this is that if you add the second event listener too late (i.e. the load event already fired) it will not be called.

Anyway, feels like a hack, but is just an idea in case you cannot find a better way to handle it.

因为看清所以看轻 2024-09-04 19:19:21

您可以使用:

gBrowser.addEventListener("DOMContentLoaded", function()
{
// Page content is loaded
}, false);

但请记住 gBrowser 引用选项卡的内容,因此这将在选择每个选项卡时检查它

You could use:

gBrowser.addEventListener("DOMContentLoaded", function()
{
// Page content is loaded
}, false);

but remember that gBrowser refers to the content of a tab so this will check every tab when it has been selected

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