I am trying to trigger events (backbutton
, pause
, resume
etc) in cordova manually from the browser (for debugging). I am doing it in the following way:
$(window).trigger('backbutton');
When we register the event handler using $(document).on('backbutton', handlerCode);
The backbutton
event gets triggered, however when we register it using the syntax in the cordova documentation:
document.addEventListener("backbutton", onBackKeyDown, false);
the event handler is not triggered. I noticed this when I used $(window).trigger('backbutton')
, the code did not hit the cordova.js file. What would be the right way to invoke events in cordova application from the browser?
I am trying to trigger events (backbutton
, pause
, resume
etc) in cordova manually from the browser (for debugging). I am doing it in the following way:
$(window).trigger('backbutton');
When we register the event handler using $(document).on('backbutton', handlerCode);
The backbutton
event gets triggered, however when we register it using the syntax in the cordova documentation:
document.addEventListener("backbutton", onBackKeyDown, false);
the event handler is not triggered. I noticed this when I used $(window).trigger('backbutton')
, the code did not hit the cordova.js file. What would be the right way to invoke events in cordova application from the browser?
-
1
Try
cordova.fireDocumentEvent('backbutton')
and see if that works better? – Kerri Shotts Commented Sep 5, 2014 at 21:19 - Tried cordova.fireDocumentEvent('backbutton') also, but the control did not return to the event handler for the backbutton – Harshit Commented Sep 6, 2014 at 11:35
- You said "What would be the right way to invoke events in cordova application from the browser?". You can't test those events on the browser, you need a phone – Emre Commented Sep 6, 2014 at 20:54
- Yes, but my requirement is to simulate firing events in browser during development, before creating the app and deploying to the phone. All I need is a way to fire events so that after firing events, the control returns to the event handler. – Harshit Commented Sep 7, 2014 at 3:58
1 Answer
Reset to default 6It is possible to fire the events from browser. In order to fire the events, it is required to either fireWindowEvent or fireDocumentEvent.
To fire the pause, resume, online, offline, backbutton, menubutton, searchbutton, startcallbutton, endcallbutton, volumeupbutton, volumedownbutton, use the fireDocumentEvent. eg, firing 'pause' event:-
cordova.fireDocumentEvent('pause',{});
In order to fire events related to battery, use fireWindowEvent. eg, firing 'batterycritical' event:-
cordova.fireWindowEvent('batterycritical', {"level":"20","isPlugged":true});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744712585a4589429.html
评论列表(0条)