Phonegap 1.7中的Childbrowser插件只能是第一次打开

时间:2012-05-17 08:27:54

标签: iphone cordova childbrowser

Phonegap 1.7中的Childbrowser插件只能是第一次打开。我正在使用Phonegap 1.7和Childbrowser。只有儿童浏览器第一次正常工作。在我关闭Childbrowser(按下完成按钮)后,当我试图打开它时,它没有再打开。

我的代码是:

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

当我点击链接时,弹出Childbrowser并显示该页面。我点击“完成”然后返回。但是,当我点击链接或其他链接时,Childbrowser不再弹出,但每次都会显示警告“点击”。

P.S。我从here

下载了Childbrowser插件

3 个答案:

答案 0 :(得分:3)

我也遇到过这个问题,Cordova 2.0.0与jQuery Mobile 1.1.1一起使用。我设置链接的代码如下:

$(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();
    });
  }
}

注意:pageinit event与通常的$(document).ready()类似,但适用于jQuery Mobile。

这样,ChildBrowser在第一个链接点击时打开,但在关闭后不再打开。为了解决这个问题,我在event.preventDefault();之后添加了这两行:

event.stopImmediatePropagation();
return false;

那是为我做的!

答案 1 :(得分:2)

我使用https://github.com/phonegap/phonegap-plugins/blob/master/iPhone/ChildBrowser/遇到了同样的问题。

我解决了它黑客攻击ChildBrowser.js评论4行,如下所示。我意识到这两种方法都被调用,所以可能会发生某种冲突。我希望有所帮助。

ChildBrowser.prototype.showWebPage = function(loc) { 
//  if (typeof PhoneGap !== "undefined")
//  {
//      PhoneGap.exec("ChildBrowserCommand.showWebPage", loc);
//  }
    if (typeof Cordova !== "undefined")
    {
        Cordova.exec("ChildBrowserCommand.showWebPage", loc);
    }
};

答案 2 :(得分:1)

我对cordova 1.9也有同样的问题。

我使用的插件版本有不同的showWebPage函数代码:

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

我在日志中注意到,当子浏览器失败时,javascript'click'函数会快速连续调用两次。有时它会在第一次点击时发生,有时会在5或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>.

我已尝试在点击按钮后从按钮中删除点击事件,并在childBrowser.onClose事件上重新应用它,这似乎有助于儿童浏览器崩溃问题。