2

So I'm setting up the Child Browser plugin in Xcode for my phonegap app and was having some issues with it. First off, just to make sure its structured correctly in Xcode, I have all the native files in my plugins folder along with ChildBrowser.bundle for the icons.
Now for the html side, I have a my cordova.js and childbrowser.js files in my head followed by this

 <script type="text/javascript">
    function onDeviceReady() {

        var root = this;
        cb = window.plugins.childBrowser;

        if(cb != null) {
        cb.onLocationChange = function(loc){ root.locChanged(loc); };
        cb.onClose = function(){root.onCloseBrowser(); };
        cb.onOpenExternal = function(){root.onOpenExternal(); }
        }
    }

    function onCloseBrowser() {
        console.log("onCloseBrowser!");
    }

    function locChanged(loc) {
        console.log("locChanged!");
    }

    function onOpenExternal() {
        alert("onOpenExternal!");
    }

</script>

Then for my <a> tag I used the onClick event that is used in the github example Here

<a onclick="childBrowser.showWebPage('http://google.com');" href="#">Test</a>

But when I try it in the simulator, nothing really happens and the consol log doesn't even show any activity. I'm I doing this right or what? Any help is appreciated. Im using phonegap 2.6.0

mhartington
  • 6,905
  • 4
  • 40
  • 75

3 Answers3

4

This will help you to add the child browser.

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

and Also Installing Cordova Plugins with Phonegap - no Cordova.plist

I integrated it successfully by above the link and below are the steps.

1) Copy all the files in "ChildBrowser" and paste it in "Plugin" folder of PhoneGap 2.6.0 Project.

2) Add Framework from "Plugin" as shown below screenshot.

enter image description here

3) Include the "ClildBrowser.js" into "www/index.html"

4) From Xcode, add the files into "Plugin" Folder.

5) Follow the code mentioned at https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ChildBrowser

6) Enjoy.

Community
  • 1
  • 1
AvtarSingh Suchariya
  • 1,992
  • 1
  • 20
  • 25
  • 1
    Yeah followed your steps and went back to the github to makes sure it was the right javascript to initiate it but it still wouldn't work. I go to tap the link and nothing happens. But thanks for the help – mhartington May 07 '13 at 12:59
  • Hello I just implemented. If you want I can provide you by any mean so that your work get started. Meanwhile I will push on github so that you can access it. Let me know, if any other way I can help. :) – AvtarSingh Suchariya May 07 '13 at 13:14
  • hey thanks for the offer. I appreciate all the help you're offering. whats the link to your github? – mhartington May 07 '13 at 13:18
2

Update: If your using Phongap 2.0 or above, you don't need an external plugin . Phonegape 2.0 , and above come with InAppBrowser which is ChildBrowser but very effective and time saving you dont need to go through all this painful process. to setup InAppBrowser

steps:

1- in config.xml add :

<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>

2- Create Function and call that function once phonegap is loaded "inside OnDeviceReady() or after"

function externalWeb(url) {
    console.log("Initializing InAppBrowswer");

    var ref = window.open(url, '_blank', 'location=yes', 'EnableViewPortScale=yes');

    ref.addEventListener('loadstart', function(event) {
        console.log("start loading external link  :" + event.url);
    });

    ref.addEventListener('loadstop', function(event) {
        console.log("External link lodaded without any problem  : " + event.url);
    });

    ref.addEventListener('loaderror', function(event) {
        console.log("There is error in loading External link :" + event.url);
        alert('error: ' + event.message);
    });

    ref.addEventListener('exit', function(event) {
        console.log("External link is closed now :" + event.type + "link :" + event.url);
    });
}

3- now to open a link call the function above with the URL as string

var targetURL="http://www.google.co.uk";
externalWeb(targetURL);

For more information follow the link InAppBrowser

Paritosh
  • 2,097
  • 3
  • 30
  • 42
0
<feature name="ChildBrowserCommand">
    <param name="ios-package" value="ChildBrowserCommand" />
</feature>

Do remember to get the latest plugin code , since phonegap has changed the way parameters are passed to native .m file For ex :

- (void)showWebPage:(CDVInvokedUrlCommand*)command 

and in .h file

@property (nonatomic, strong) ChildBrowserViewController* childBrowser;

-(void)showWebPage:(CDVInvokedUrlCommand*)command;
Ecko123
  • 308
  • 1
  • 4
  • 16