javascript - Firing events in Cordova applications - Stack Overflow

I am trying to trigger events (backbutton, pause, resume etc) in cordova manually from the browser (for

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?

Share Improve this question edited Jun 23, 2020 at 19:16 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Sep 5, 2014 at 12:35 HarshitHarshit 1232 silver badges11 bronze badges 4
  • 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
Add a ment  | 

1 Answer 1

Reset to default 6

It 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

相关推荐

  • javascript - Firing events in Cordova applications - Stack Overflow

    I am trying to trigger events (backbutton, pause, resume etc) in cordova manually from the browser (for

    21小时前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信