Search code examples
angularjscordovacordova-plugins

Cordova inAppBrowser causes application crash, added angularjs


I have created a cordova project and I want to use the inAppBrowser. I have added the plugin like this from CLI cordova plugin add org.apache.cordova.inappbrowser and I have added angularjs to my project. I have cleaned the project in eclipse and also built from CLI.

My applicable html:

<input type="submit" value="FB test button" ng-click="loginFaceBook()"/>

My applicable code in controller:

$scope.loginFaceBook = function() {

    toastr.warning("Button pressed");

    loginService.loginProviders().success(function(data, status, headers, config) {

        //window.open(data[0].Url, '_blank', 'location=yes');
        var facebook = window.open(encodeURI('www.google.com'), '_blank', 'location=yes');
        facebook.addEventListener('loadstart', function(event) { console.log('start: ' + event.url); });
        facebook.addEventListener('loadstop', function(event) { console.log('stop: ' + event.url); });
        facebook.addEventListener('loaderror', function(event) { console.log('error: ' + event.message); });
        facebook.addEventListener('exit', function(event) { console.log(event.type); });

    }).error(function(data, status, headers, config) {
        // If list of providers are not returned
        toastr.error("Failure");
    });
};

The code gets fired and I get the following alert in my app:

Application Error There was a network error (file:///android_asset/www/www.google.com)

I am using cordova 3.4.0

Thank you in advance and let me know if you need additional information.

EDIT replaced alert with console.log, still getting the same error


Solution

  • try

    encodeURI('http://www.google.com')
    

    instead of

    encodeURI('www.google.com')