admin管理员组文章数量:1391976
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});
本文标签: javascriptFiring events in Cordova applicationsStack Overflow
版权声明:本文标题:javascript - Firing events in Cordova applications - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744712584a2621215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论