在科尔多瓦应用中发射事件 [英] Firing events in Cordova applications
问题描述
我正在尝试从浏览器手动触发事件(backbutton,pause,resume等)(用于调试)。我以下列方式进行:
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');
< backbutton',handlerCode);
backbutton事件被触发,但是当我们使用cordova文档中的语法注册它时
the backbutton event gets triggered, however when we register it using the syntax in the cordova documentation
document.addEventListener("backbutton", onBackKeyDown, false);
不触发事件处理程序。我注意到,当我使用 $(window).trigger('backbutton')
时,代码没有打到cordova.js文件。从浏览器调用cordova应用程序的正确方法是什么?
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?
推荐答案
可以从浏览器中触发事件。为了触发事件,需要fireWindowEvent或fireDocumentEvent。
It is possible to fire the events from browser. In order to fire the events, it is required to either fireWindowEvent or fireDocumentEvent.
要启动暂停,恢复,在线,离线,后退按钮,menubutton,搜索按钮,startcallbutton, endcallbutton,volumeupbutton,volivedownbutton,使用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',{});
为了触发与电池相关的事件,请使用fireWindowEvent。例如,发射电子政治事件: -
In order to fire events related to battery, use fireWindowEvent. eg, firing 'batterycritical' event:-
cordova.fireWindowEvent('batterycritical', {"level":"20","isPlugged":true});
这篇关于在科尔多瓦应用中发射事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!