Reputation: 738
On the app start I want to execute a JavaScript Function.
I tried to work on this with index as having - data-page="index" and using below function:
myApp.onPageInit('index', function (page) {
// "page" variable contains all required information about loaded and initialized page
})
But this function doesn't work when the application is just started.
Upvotes: 1
Views: 5141
Reputation: 97
Try to change
$$(document).on('deviceready', function() {
// Your content here
});
For
$$(document).on('DOMContentLoaded', function(){
// Your content here
});
Upvotes: 0
Reputation: 828
You have to trigger it.
myApp.onPageInit('index', function() {
// Code here
}).trigger();
Use .trigger()
only for index route. You can read more in framework7 documentation.
Update
You can also check the issue conversation in framework7 github repo.
Upvotes: 1
Reputation: 1465
YOu can try this:
window.onload = function(){ document.addEventListener("deviceready", onDeviceReady, false); }
function onDeviceReady() { // your device ready logic here }
Edit:
We can do this in pure JavaScript (although this will not work in all browsers):
var doSomething = function (event) { . . . };
window.addEventListener('DOMContentLoaded', doSomething);
But we can do it more easily with jQuery, and it will work cross-browser:
$(window).ready(doSomething);
This can be shortened further to:
$(doSomething);
In all the above examples, doSomething is a JavaScript function.
Upvotes: 0