Unable to redirect error page using InApp Browser using Cordova

117 views
Skip to first unread message

mad pop

unread,
Jun 22, 2016, 10:27:48 AM6/22/16
to phonegap
Hi 

i am using InApp browser for calling a web page and displaying it . I called successfully   a web page  below is the code 

 var inAppBrowserbRef;
        
        inAppBrowserbRef = window.open('http://www.google.in', '_self', 'location=no,toolbar=no');
       
        inAppBrowserbRef.addEventListener('loadstart', inAppBrowserbLoadStart)
        inAppBrowserbRef.addEventListener('loadstop', inAppBrowserbLoadStop);
        inAppBrowserbRef.addEventListener('loaderror', inAppBrowserbLoadError);
        inAppBrowserbRef.addEventListener('exit', inAppBrowserbClose);


        function inAppBrowserbLoadStart(event) {

            //navigator.notification.activityStart("Please Wait", "loading....");

            //alert(event.type + ' - ' + event.url);
            var options = { dimBackground: true };
            SpinnerPlugin.activityStart("Loading...", options);
            if (navigator.connection.type == Connection.NONE) {
                navigator.notification.alert('An internet connection is required to continue', alertSuccess, "Network Error", "Ok");
            }
            function alertSuccess() {
                navigator.app.exitApp();
            }


        }

        function inAppBrowserbLoadStop(event) {
            //navigator.notification.activityStop();
            // alert(event.type + ' - ' + event.url);
            // navigator.notification.activityStop("Please Wait", "loading Completed");
            SpinnerPlugin.activityStop();
            if (navigator.connection.type == Connection.NONE) {
                navigator.notification.alert('An internet connection is required to continue', alertSuccess, "Network Error", "Ok");
            }
            function alertSuccess() {
                navigator.app.exitApp();
            }

        }

        function inAppBrowserbLoadError(event) {
            //navigator.notification.activityStop();

            // alert(event.type + ' - ' + event.message);
            SpinnerPlugin.activityStop();
            if (navigator.connection.type == Connection.NONE) {
                navigator.notification.alert('An internet connection is required to continue', alertSuccess, "Network Error", "Ok");
            }
            function alertSuccess() {
                navigator.app.exitApp();
            }
        }

        function inAppBrowserbClose(event) {
            //navigator.notification.activityStop();
            //alert(event.type);
            SpinnerPlugin.activityStop();
            inAppBrowserbRef.removeEventListener('loadstart', iabLoadStart);
            inAppBrowserbRef.removeEventListener('loadstop', iabLoadStop);
            inAppBrowserbRef.removeEventListener('loaderror', iabLoadError);
            inAppBrowserbRef.removeEventListener('exit', iabClose);
        }

        //this helps in exiting back buttin
        document.addEventListener("backbutton", function (e) {
            e.preventDefault();
            navigator.notification.confirm("Are you sure want to exit from App?", onConfirmExit, "Confirmation", "Yes,No");
        }, false);

        function onConfirmExit(button) {
            if (button == 2) { //If User select a No, then return back;
                return;
            } else {
                navigator.app.exitApp(); // If user select a Yes, quit from the app.
            }
        }




ok now the problem is i able to call it online and whenever it is offline or unable to connect to the page it is displaying error page unable to connect  Instead of the i want to display  local page and here i already tried of using  IF condition and checked the code but its not working . below is the code




document.addEventListener('resume', onResume.bind(this), false);
        document.addEventListener("offline", onOffline, false);
        document.addEventListener("online", onOnline, false);

        function onOffline() {
            if (navigator.connection.type === Connection.NONE) {
                navigator.notification.alert('An internet connection is required to continue', alertSuccess, "Network Error", "Ok");
                window.open('error.html', '_self', 'location=no,toolbar=no');
            }
            function alertSuccess() {
                navigator.app.exitApp();
            }
        }

        function onOnline() {
            if (navigator.connection.type === Connection.WIFI) {
                navigator.notification.alert("Onlline");
                window.open('http://www.google.com', '_self', 'location=no,toolbar=no');
            }
           
        }

Please check the issue and give any suggestions

Reply all
Reply to author
Forward
0 new messages