PhoneGap Build + Cordova + ChildBrowser Error

走远了吗. 提交于 2019-12-11 19:47:38

问题


Here is my code:

<script src="include/cordova.js" type="text/javascript"></script> <script src="include/sencha-touch-all.js" type="text/javascript"></script> <script type="text/javascript" charset="utf-8" src="include/childbrowser.js"></script> <link href="include/sencha-touch.css" rel="stylesheet" type="text/css" />

var childBrowser = null;
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) {
   document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
function onDeviceReady(){
  console.log("PhoneGap is Ready");
  childBrowser = ChildBrowser.install();
}
function openChildBrowser(url)
{
        try {
            //both of these should work...
            var cb = new ChildBrowser();
            console.log(cb);
            cb.showWebPage('http://www.google.com');
        }
        catch (err)
        {
            alert(err);
            console.log(err);
        }
}

...

There is some more code that is unrelated but when I call openChildBrowser() I receive the following error:

Uncaught TypeError: Object #<Object> has no method 'exec' Which I believe is in reference to childbrowser calling exec on the cordova object.

When I look at the cordvoa object I don't see an exec function anywhere...

Any ideas?


回答1:


Is this for iOS or android? This code will work on both. I've found that when using the var cb = new ChildBrowser() that there can be errors. I think a clean up of the way that ChildBrowser is called is in order, but I do not have the time right now to do so. This method will work. Promise :) ps - if you're doing this for iOS there is an example of this working.

ChildBrowser.install();
window.plugins.childBrowser.showWebPage('http://www.google.com');



回答2:


As far as I'm aware, ChildBrowser is not yet fully compatible with cordova.

In any case, it sounds like cordova isn't finishing initialization before you try to communicate with the ChildBrowser plugin.

Try connecting up weinre or something and testing that you can open child browser manually after cordova is fully initialized. Make sure this code is after cordova in script load order. Also make sure you're using the latest versions of everything.




回答3:


If you use async java script loading a.k.a Lazy Loading, you maybe get this error.

In my case; I was using iframe in main html document. And In IFrame, I load and run all advertise scripts async. After that, I started to get Uncaught TypeError: Object # has no method 'exec'.

I don't know HOW & WHY but I guess this type of usage causes to web-kit misunderstood.

PS:Using sencha or not using, this error occured. So it isn't related with sencha-touch-all.




回答4:


I have been struggling with ChildBrowser and Phonegap on iOS. I noticed you can only get ChildBrowser working properly when 'installed' after the deviceready event. This event is only triggered if your html is valid and complete.

I discovered that if you refer to an image which is not actually present, typo of file name or image was just not there because design guys had not yet given it (my scenario), the deviceready just doesn't fire. And as a result the plugin would not install (correctly).

Registering for the deviceready event in the onload event is the way to go and works as long as your html is good and nothing is missing.

Hope this helps other people.




回答5:


update you phonegap / cordova to 1.7.0 and fetch childbrowser latest code from github. it should work fine.




回答6:


I ended up starting over and using Eclipse and the Phonegap SDK. Was able to get this working that way without using the build service.

This might help some people:

http://phonegap.com/start#android

https://github.com/phonegap/phonegap-plugins/tree/master/Android/ChildBrowser




回答7:


You can not use the childbrowser plugin for desktop browser. It works only on device or simulator so you are getting this error.



来源:https://stackoverflow.com/questions/10308818/phonegap-build-cordova-childbrowser-error

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