0

I'm trying to create a web app using phonegap. And I was using the code below and it worked fine.

   <script type="text/javascript" charset="utf-8">
            document.addEventListener("deviceready", onDeviceReady, false);

            function onDeviceReady() {

                window.location.href = 'https://abc.xyz/';
            }
   </script>

Now I need to check my internet connectivity too, so as I used the above code with internet connection code but it navigates me to my default browser(chrome) on entering inside the application. Can any one help me with the solution. Here is the code below

   <script>
        $(document).ready(function () {
            document.addEventListener("deviceready", onDeviceReady, false);
            document.addEventListener("online", onOnline, false);
            document.addEventListener("offline", onOffline, false);
            function onDeviceReady() {
             window.location.href = 'https://abc.xyz/';
                alert(" ready");
            }

            function onOnline() {
                alert("connected");
                window.location.href = 'https://abc.xyz/';
            }

            function onOffline() {
                debugger;
                console.log("lost connection");

                navigator.notification.alert(
                    'Please Check your internet connection.', // message
                    null, // callback
                    'Sample', // title
                    'OK' // buttonName
                );
            }
        });
    </script>
Jqa
  • 11
  • 4

1 Answers1

0

Add inappbrowser Cordova Plugins:

cordova-plugin-inappbrowser

cordova plugin add cordova-plugin-inappbrowser
function onDeviceReady() {
                //onDeviceReaddy

                window.open = cordova.InAppBrowser.open;
                window.open('https://abc.xyz/', '_blank', 'location=yes,enableviewportscale=yes');
                }

It's load https://abc.xyz/ this URL within the app.

Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41