How to deal with cordova plugin when developing in browser?

微笑、不失礼 提交于 2019-12-02 11:29:10

As cordova.js is only available when you are running application in device or emulator. So there is no way that you can use cordova plugins in browsers.As you need to put a check if(navigator.globalization) on every plugin call for testing on browsers, so i will suggest you to make your own wrapper or functions above these calls, some sort of global function which will call these plugins functions. Here is a sample with plain javascript.

function MyGlobalizationService(){
};

MyGlobalizationService.prototype.getPreferredLanguage = function(onSuccess, onError){
 if(navigator.globalization) {
     navigator.globalization.getPreferredLanguage(onSuccess, onError);
 }
}

window.myGlobalizationService = new MyGlobalizationService();

And then use window.myGlobalizationService functions anywhere in your application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!