Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need the document ready inside deviceready?

In phonegap do I need the $(document).ready(...) inside the deviceready event function? Can I be sure that document is loaded when the deviceready event is called?

Example:

document.addEventListener('deviceready', 
   function() {
            $(document).ready(function() { // is this too much? 
                initCampusWeb(); 
            });
        }, false);
like image 329
OOPDeveloper89 Avatar asked Dec 28 '25 19:12

OOPDeveloper89


1 Answers

The way that this works is jQuery(document).ready() fires first and then deviceready fires.

I generally set up my code like this:

jQuery(document).ready(function () {
    // do document ready stuff
}).on('deviceready', function () {
    // do deviceready stuff, put all calls to plugins in here
});

So the question as to where initCampusWeb goes depends on what you are doing inside that function. If it uses plugins, put it inside the deviceready handler.

like image 108
unobf Avatar answered Dec 30 '25 07:12

unobf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!