Software Archive
Read-only legacy content
17061 Discussions

noob question onlaunch or oncreate alernative

zack_m_
Beginner
323 Views

Hello i have a noob question if someone could help im sure its a quick answer. Im used to languages like VB and im trying to learn JS

If i want a script or a variable to run when a page/app loads/launches where would i put it?

thanks for the help i was having a hard time googling it specificly for intel xdk

0 Kudos
1 Solution
Pamela_H_Intel
Moderator
323 Views

Zack,

To check if the app is loaded and ready - if you really want to understand when the best time is to make something happen.

For understanding what happens in what sequence, take a look at the Hello Cordova app. It has a function onDeviceReady that ensures that both the DOM and the webview is ready.

Go to the PROJECTS tab -> Start a new Project (bottom left) -> Samples and Demos -> Hello Cordova

Take a look at the comments in www/xdk/init-dev.js starting at line 147 to get an understanding of the order of event firing. Then if you have the index.html file open, there is a series of tabs to the left of the name "www/index.html". Click "Find" -> "Find in Files" -> type deviceReady . . . look at lines 32-34 for example . . . you will see that the compass info is not logged until the device is ready.

Of course you can put scripts inline in index.html, but that is not recommended for cordova apps. It makes debugging harder.

View solution in original post

0 Kudos
2 Replies
Pamela_H_Intel
Moderator
324 Views

Zack,

To check if the app is loaded and ready - if you really want to understand when the best time is to make something happen.

For understanding what happens in what sequence, take a look at the Hello Cordova app. It has a function onDeviceReady that ensures that both the DOM and the webview is ready.

Go to the PROJECTS tab -> Start a new Project (bottom left) -> Samples and Demos -> Hello Cordova

Take a look at the comments in www/xdk/init-dev.js starting at line 147 to get an understanding of the order of event firing. Then if you have the index.html file open, there is a series of tabs to the left of the name "www/index.html". Click "Find" -> "Find in Files" -> type deviceReady . . . look at lines 32-34 for example . . . you will see that the compass info is not logged until the device is ready.

Of course you can put scripts inline in index.html, but that is not recommended for cordova apps. It makes debugging harder.

0 Kudos
zack_m_
Beginner
323 Views

thanks you for the info i will do this

0 Kudos
Reply