Close the child window of an Android application made using Angularjs

I am encoding an Android application with Angularjs and cordova, but I have a problem: To call oauth I need to open a new window, go to the links site and when I am on my callback, close the window.

I tried to use setInterval (or $ interval) to check every 2 seconds if I found information on calling my API. It works fine on a computer in chrome, but when I compile an application with Cordova, I never go into a loop.

So, I tried to catch an event or $ watch in the url of my new window, but I execute only once when my function changes the URL for the first time, even if my API call leads to an error.

This is my last code, but I have tried many different tests:

var newWindow = $window.open(result.res); var unwatch = $scope.$watch(window.location, function() { $http.get(url) .success(function(result) { newWindow.close(); unwatch(); $location.path('/tab/dash'); }) .error(function(error) { console.log(error); }); }); 

If you have an idea to do this work, I will be very glad.

Thanks in advance!

+1
source share
1 answer

Finally, I found a solution:

I install the cordova inAppBrowser plugin and use this code

 var windowWithings = $window.open(result.res, '_blank', 'location=no'); windowWithings.addEventListener('loadstart', function(event) { $http.get(url) .success(function(result) { windowWithings.close(); $location.path('/tab/dash'); }) .error(function(error) { console.log(error); }); }); 

Be careful if you do not add "location = no" to open, this will not work.

0
source

Source: https://habr.com/ru/post/954745/


All Articles