【问题标题】:DOMContentLoaded will be fired twice on my pageDOMContentLoaded 将在我的页面上被触发两次
【发布时间】:2021-10-29 06:31:12
【问题描述】:

在我http://www.sybase-recovery.com/outlook-repair/的页面中,我在http://www.sybase-recovery.com/wp-content/themes/datanumen/js/theme1.js写了一个非常简单的脚本theme1.js,如下:

document.addEventListener('DOMContentLoaded', function () {
    var b = 1;
});

但在调试过程中,我发现当按下 Ctrl + F5 加载页面时,DOMContentLoaded 事件会被触发两次。

我尝试在网上搜索,发现两个结果:

  1. DOMContentLoaded event firing twice for a single page load,表示 AVG 插件会导致问题,但我没有安装 AVG 插件。
  2. http://forums.mozillazine.org/viewtopic.php?f=19&t=1590225,在https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#Detecting_page_load提供了解决方案,但是链接失效了。

有没有人遇到过类似的问题?

谢谢

【问题讨论】:

    标签: javascript


    【解决方案1】:

    因为你的页面有 iframe

    <iframe width="100%" height="800px" src="http://www.sybase-recovery.com/support/documentation/outlook-repair/"></iframe>
    

    它还包含相同的 theme1.js 文件

    【讨论】:

    • 谢谢。我懂了。在直播站点中,放入iframe的页面不包含theme1.js,但是在我当前的测试站点中,我没有包含该页面,导致404未找到错误页面,其中包含theme1.js
    猜你喜欢
    • 2011-09-17
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 2014-06-28
    相关资源
    最近更新 更多