Dojo和onload事件 [英] Dojo and the onload event

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

问题描述

我们有一堆遗留页面。而我们正在尝试将dojo注入他们。然而,我们发现,任何绑定到加载事件,如

  window.addEventListener(加载 ,处理程序)

无法执行。



我从2006年读了几篇博客文章,表明dojo正在为加载事件做点事情,但是他们是旧帖子,不知道他们是否仍然有关系。



将绑定更改为使用dojo / ready功能,但有很多代码,我们希望不必全面检查。



是否可以在dojo中使用window.onload?

解决方案

p>应该可以正常工作,所以下列工作应该可以工作:

  window.addEventListener(load,function() 
console.log(on on event event on an event listener on onload event);
});

window.onload = function(){
console.log(使用onload事件处理);
};

即使Dojo也有自己的模块来等待DOM加载:

  require([dojo / domReady!],function(){
console.log(使用dojo / domReady模块处理 );
});

如果要使用AMD并加载所需的模块,则可能需要使用



但是,如果您使用窗口小部件的声明式标记,那么您将必须等到这些被解析,这是在 DOM加载之后需要的地方,这就是 dojo / ready 模块的地方对于



dojo / ready 模块不仅等待DOM加载,而且等待直到所有的声明性标记被解析成小部件。


We have a mess of legacy pages. And we're trying to inject dojo into them. We're finding, however, that any binds to a "load" event, such as

window.addEventListener("load", handler)

fail to execute.

I read a couple of blog posts from 2006 that suggests that dojo is doing something to the load event, but they're old posts and not sure if they're still relevant.

Changing the binding to use dojo/ready works, but there is alot of code and we were hoping not to have to overhaul it all.

Is it not possible to use window.onload with dojo?

解决方案

It should work just fine, so the following should work:

window.addEventListener("load", function() {
  console.log("Handled by using an event listener on the onload event");
});

window.onload = function() {
  console.log("Handled by using the onload event");  
};

Even Dojo has its own module to wait until the DOM is loaded:

require([ "dojo/domReady!" ], function() {
   console.log("Handled by using the dojo/domReady module"); 
});

If you want to work with AMD and load the modules you need, you probably want to work with the dojo/domReady! module.

However, if you're working with declarative markup for widgets, then you will have to wait until these are parsed as well, which is something that takes places after the DOM is loaded, and that's where the dojo/ready module is useful for.

The dojo/ready module not only waits until the DOM is loaded, but also waits until all declarative markup is parsed into widgets.

这篇关于Dojo和onload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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