NWJS window 加载不可用
NWJS window loaded is not available
NWJS documentation 指出打开 window 后,您必须等待 loaded
事件才能与之交互:
You should wait for the Window’s loaded
event before interacting with any of its components.
所以我尝试在打开 win 对象后为它添加一个 loaded
事件处理程序。
nw.Window.open('test.html', {}, (win) => {
win.showDevTools()
win.addEventListener("loaded", () => {
console.log("NW Window loaded not working...")
})
}
我收到以下错误:
Uncaught TypeError: win.addEventListener is not a function
如何在 NWJS 中监听 NWWindow 事件?旁注:我 CAN 监听 DOM window 加载事件,但这不一样是吗?
nw.Window.open('test.html', options, (win) => {
win.showDevTools()
win.window.addEventListener("load", () => {
console.log("dom window load IS working...")
})
}
nw.Window上有一个关于如何使用事件侦听器的示例:
nw.Window.open('test.html', {}, win => {
win.showDevTools();
win.on("loaded", () => {
console.log("NW Window loaded not working...")
})
}
来自 here 的示例,我对其进行了更改以适合您的问题
- 编辑:我将 nw.Window.get() 更改为 win
addEventListener
来自 DOM。请参阅 https://nodejs.org/api/events.html#events_emitter_addlistener_eventname_listener,然后重试。 console
在这里也可以作为 win.window.console
使用。
NWJS documentation 指出打开 window 后,您必须等待 loaded
事件才能与之交互:
You should wait for the Window’s
loaded
event before interacting with any of its components.
所以我尝试在打开 win 对象后为它添加一个 loaded
事件处理程序。
nw.Window.open('test.html', {}, (win) => {
win.showDevTools()
win.addEventListener("loaded", () => {
console.log("NW Window loaded not working...")
})
}
我收到以下错误:
Uncaught TypeError: win.addEventListener is not a function
如何在 NWJS 中监听 NWWindow 事件?旁注:我 CAN 监听 DOM window 加载事件,但这不一样是吗?
nw.Window.open('test.html', options, (win) => {
win.showDevTools()
win.window.addEventListener("load", () => {
console.log("dom window load IS working...")
})
}
nw.Window上有一个关于如何使用事件侦听器的示例:
nw.Window.open('test.html', {}, win => {
win.showDevTools();
win.on("loaded", () => {
console.log("NW Window loaded not working...")
})
}
来自 here 的示例,我对其进行了更改以适合您的问题
- 编辑:我将 nw.Window.get() 更改为 win
addEventListener
来自 DOM。请参阅 https://nodejs.org/api/events.html#events_emitter_addlistener_eventname_listener,然后重试。 console
在这里也可以作为 win.window.console
使用。