Childbrowser plugin in Phonegap 1.7 can only be opened for the first time

The Childbrowser plugin in Phonegap 1.7 can only be opened for the first time. I am using Phonegap 1.7 and Childbrowser. Only the first time a child browser is running. After I closed Childbrowser (clicked "Finish"), it does not open again when I tried to open it.

My code is:

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

When I click the link, Childbrowser pops up and shows the page. I click Finish and return. But when I click a link or another link, Childbrowser no longer appears, but a β€œclick” warning is displayed every time.

ps I downloaded the Childbrowser plugin from here

+4
source share
3 answers

I also had this problem with Cordova 2.0.0 in conjunction with jQuery Mobile 1.1.1. My code for setting up my links looked like this:

 $(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 pageinit like a regular $(document).ready() , but for jQuery Mobile.

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

 event.stopImmediatePropagation(); return false; 

It did it for me!

+3
source

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

I decided that he hacked ChildBrowser.js by commenting out 4 lines, as shown below. I realized that these two methods are called so that some kind of conflict can occur. Hope this helps.

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

I have the same problem with corridor 1.9.

The plugin version that 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); }; 

In my logs, I noticed that when the child browser crashes, the javascript 'click' function is called twice in a row. Sometimes this happens at 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 tried removing the click event from the button after it was clicked and re-applying it to the childBrowser.onClose event, it looks like this helped the issue with the child browser.

+1
source

Source: https://habr.com/ru/post/1412933/


All Articles