The window.onload event is not firing in my 8th Wall hosted project. How do I listen for the onload event in 8th Wall?
The loading sequence of cloud editor projects is head.html
> app.js
> body.html
. By the time your code in app.js
is executed, the onload
event has likely already fired (while the default splash screen is being displayed).
A better/safer approach is to listen on events such as realityready (AFrame) or xrloaded events (when XR8 is on the window), or within init() of an AFrame component.
1 Like
If you wish to make DOM manipulations programmatically after body.html
is loaded, a common pattern is to put code similar to the following at the end of app.js
:
const onxrloaded = () => {
// Run any code that you'd like to execute after the body.html is loaded.
}
window.XR8 ? onxrloaded() : window.addEventListener('xrloaded', onxrloaded)
1 Like