windows.onload事件未在IE8中触发 [英] The window.onload event is not firing in IE8

查看:526
本文介绍了windows.onload事件未在IE8中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我删除了这个javascript,尽可能简单,但它仍然无法在IE8中运行。

I stripped down this javascript to be as simple as possible, and it's still not working in IE8.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload !== 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}

function callkits() {
    alert('Kits: Bug testing');
}

//addLoadEvent(callkits);
//window.onload = callkits;
window.onload = function() {
    callkits();
};

两个注释掉的方法和活动方法都没有在IE8中做任何事情。 Javascript已启用。 (直接在函数外部调用 alert 确实有效。)我在这里撕扯我的头发。

Neither of the two commented out methods, nor the active method, do anything in IE8. Javascript is enabled. (Calling alert directly, outside a function, does work.) I'm tearing my hair out here.

编辑

好的,现在更简单了:

alert('Before onload.')

window.onload = function() {
    alert('Onload');
};

alert('After onload');

在Firefox,Opera,Safari和Chrome中,我得到Before onload,After onload ,然后页面出现,然后Onload。在IE8中,最后一步不会发生。 window.onload 根本就没有解雇。

In Firefox, Opera, Safari, and Chrome, I get "Before onload", "After onload", then the page appears, then "Onload". In IE8, that last step doesn't happen. window.onload simply isn't firing.

推荐答案

标准onload如果使用HTML defer 命令调用另一个脚本,则事件将无效。

The standard onload event won't work if another script is called using an HTML defer command.

< script for =windowevent =onloaddefer =1> products.related();< / script>

更改以上内容以使用标准 addLoadEvent()功能使其正常工作。

Changing the above to use the standard addLoadEvent() function made it work.

这篇关于windows.onload事件未在IE8中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆