Childbrowser plugin in Phonegap 1.7 can open only

2020-07-20 00:01发布

Childbrowser plugin in Phonegap 1.7 can open only for the first time. I'm using Phonegap 1.7 and Childbrowser. Only for the first time child browser is working. After I closed the Childbrowser (pressed the done button) it's not opening again when I tried to open it.

My code is this:

$("a[target=_blank]").bind('click', function(e) {
  e.preventDefault();
  var thisUrl = $(this).attr('href');
  cb.showWebPage(thisUrl);
  alert("click");
}); 

When I click a link, the Childbrowser pops up and shows the page. I click "Done" and return. But when I click the link or another link, the Childbrowser doesn't pop any more, but the alert "click" shows every time.

p.s. I downloaded the Childbrowser plugin from here

3条回答
太酷不给撩
2楼-- · 2020-07-20 00:16

I had the same problem using https://github.com/phonegap/phonegap-plugins/blob/master/iPhone/ChildBrowser/.

I solved it hacking ChildBrowser.js commenting the 4 lines as shown below. I realized that the two methods were being called so some kind of conflict might be happened. I hope that helps.

ChildBrowser.prototype.showWebPage = function(loc) { 
//  if (typeof PhoneGap !== "undefined")
//  {
//      PhoneGap.exec("ChildBrowserCommand.showWebPage", loc);
//  }
    if (typeof Cordova !== "undefined")
    {
        Cordova.exec("ChildBrowserCommand.showWebPage", loc);
    }
};
查看更多
唯我独甜
3楼-- · 2020-07-20 00:21

I have the same problem with cordova 1.9.

The version of the plugin I used has different code for the showWebPage function:

// Show a webpage, will result in a callback to onLocationChange
ChildBrowser.prototype.showWebPage = function(loc)
{
    cordovaRef.exec("ChildBrowserCommand.showWebPage", loc);
};

I have noticed in my logs that when the child browser fails, the javascript 'click' function is called twice in quick succession. Sometimes it happens on the first click, sometimes it will be after 5 or 6.

2012-07-27 09:27:12.155 XX[10562:707] [INFO] JS :: Should open in childBrowser
2012-07-27 09:27:12.158 XX[10562:707] Opening Url : http://www.google.co.uk/
2012-07-27 09:27:12.160 XX[10562:707] [INFO] JS :: Should open in childBrowser
2012-07-27 09:27:12.161 XX[10562:707] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> Application tried to present modally an active controller <MainViewController: 0x157e50>.

I have tried removing the click event from the button once it has been clicked, and re-applying it on the childBrowser.onClose event, this does seems to have helped the child browser crashing issue.

查看更多
【Aperson】
4楼-- · 2020-07-20 00:26

I also had this issue, with Cordova 2.0.0, in conjunction with jQuery Mobile 1.1.1. My code to set up my links looked like:

$(document).bind("pageinit", function() {
  onDeviceReady();
});
function onDeviceReady(){
  var root = this;
  cb = window.plugins.childBrowser;
  if (cb != null) {
    $('a[target="_blank"]').click(function(event){
      cb.showWebPage($(this).attr('href'));
      event.preventDefault();
    });
  }
}

Note: The pageinit event is like the usual $(document).ready() but for jQuery Mobile.

With that, ChildBrowser opened on the first link click, but then not again after closing it. To fix, I added these two lines after event.preventDefault();:

event.stopImmediatePropagation();
return false;

That did it for me!

查看更多
登录 后发表回答