Childbrowser plugin in Phonegap 1.7 can open only for the first time

﹥>﹥吖頭↗ 提交于 2019-12-06 04:56:56

问题


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


回答1:


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!




回答2:


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:


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.



来源:https://stackoverflow.com/questions/10632203/childbrowser-plugin-in-phonegap-1-7-can-open-only-for-the-first-time

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