Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChildBrowser Phonegap not working

After searching for a suitable way to open a browser within my app, i came across ChildBrowser, which looked like it offered everything I was after. After following a few tutorials, i cannot seem to get the plugin to work. I have edited my PhoneGap.plist file for external hosts with a value of "*", I have added in the plugins the ChildBrowserCommand, but when ever i run the application, nothing happens when i click the link. I have the following code in the head of my document;

<script type="text/javascript">
    var childBrowser;

    function onBodyLoad ()
    {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    //Phonegap ready to go
    function onDeviceReady()
    {
        alert("PhoneGap is ready");
        childBrowser = ChildBrowser.install();
    }

    function openChildBrowser(url)
    {
        try {
            window.plugins.childBrowser.ShowWebPage(url);
            //childBrowser.showWebPage(url);
        }
        cathc(err)
        {
            alert(err);
        }
    }

</script>

I have the ChildBrowser included straight after my phoneGap.js file but cannot seem to get it to run and i get no errors logged in the console. Does anyone know what is wrong or at least point me in the right direction?

like image 854
JPK Avatar asked Feb 19 '26 19:02

JPK


2 Answers

This code below works for me.

<!DOCTYPE html>
<html>
<head>
    <title>My External Page</title>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>

    <!--iPhone on Safari Standalone mode-->
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <!--Hide iPhone on Safari Native Top Status Bar-->
    <meta name="apple-mobile-web-app-status-bar-style" content="default" />
    <link rel="shortcut icon" href="favicon.ico" />

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />

    <script type="text/javascript" src="cordova-2.1.0.js"></script>
    <script type="text/javascript" src="childbrowser.js"></script>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

    <script type="text/javascript">

        document.addEventListener("deviceready", loaded, false);

        function loaded()
        {
            if (console)
            {
                console.log("cordova loaded");
            }
        }

        function showExternalPage()
        {
            if (console)
            {
                console.log("in show pmt page");
            }

            Cordova.exec("ChildBrowserCommand.showWebPage", "http://www.google.com/" );
        }

        </script>

</head>

<body>

    <div data-role="page" id="myExternalLauncherPage" data-theme="a">

        <div data-role="content">

            <ul data-role="listview" data-inset="true">

                <li>
                    <button type="submit" data-theme="b" id="launcherButton" onclick="showExternalPage()">Launch Google</button>
                </li>
            </ul>

        </div>

    </div>

</body>

like image 146
Rayman Aeron Avatar answered Feb 22 '26 13:02

Rayman Aeron


My partner wrote a step-by-step tutorial for adding the ChildBrowser plug-in to a PhoneGap Android project here.

like image 24
Paul Beusterien Avatar answered Feb 22 '26 13:02

Paul Beusterien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!