Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange phonegap device ready event behaviour
    primarykey
    data
    text
    <p>I am trying to get the device ready event to work on the phonegap 3 helloworld default app.</p> <p>html</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="format-detection" content="telephone=no" /&gt; &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /&gt; &lt;link rel="stylesheet" type="text/css" href="css/index.css" /&gt; &lt;title&gt;Hello World&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="app"&gt; &lt;h1&gt;PhoneGap&lt;/h1&gt; &lt;div id="deviceready" class="blink"&gt; &lt;p class="event listening"&gt;Connecting to Device&lt;/p&gt; &lt;p class="event received"&gt;Device is Ready&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript" src="phonegap.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; app.initialize(); &lt;/script&gt; &lt;/body&gt; </code></pre> <p></p> <p>javascript</p> <pre><code>var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicity call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); alert('welcome!'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; </code></pre> <p>This code works ok and will fire my welcome alert when I open the app. However if I comment out either of the lines:</p> <pre><code>&lt;p class="event listening"&gt;Connecting to Device&lt;/p&gt; &lt;p class="event received"&gt;Device is Ready&lt;/p&gt; </code></pre> <p>The welcome alert will no longer fire. What is going on here I have no idea what mechanism phonegap is using to create this kind of behavior?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload