什么时候应该在Electron中使用app.on(ready)和$(document).ready() [英] When should you use app.on(ready) and $(document ).ready() in Electron
问题描述
各个处理程序的回调函数何时执行?
When do the call back functions for the respective handlers execute?
推荐答案
在主流程中
当您的应用完成初始化并准备打开浏览器窗口时,会触发 app
上的就绪"事件.由于在此之前您无法打开窗口,因此可以使用回调函数来创建BrowserWindow.有关示例代码,请参见电子教程.
In the main process
The 'ready' event on app
is fired when your app finished initializing and is ready to open a browser window. Since you can't open a window before that, you use the callback function to create your BrowserWindow. See the electron tutorial for example code.
拥有BrowserWindow后,可以在其中加载HTML.这是DOM准备就绪的时候.在准备好DOM之前,您无法执行操作DOM的JavaScript.JQuery为您检测到此状态.此答案很好地说明了其工作原理.
When you have your BrowserWindow, you can load your HTML in it. This is when the DOM is ready. You can't execute JavaScript that manipulates the DOM until it is ready. JQuery detects this state for you. This answer explains nicely how this works.
这篇关于什么时候应该在Electron中使用app.on(ready)和$(document).ready()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!