I am trying to create a simple mobile app where in the user will login with oauth login on our django server. User will first try to perform an action if the user is not authenticated the server will send an error and depending up on the error user will be shown a modal with facebook, twitter and google button this button directs the user to the server and from there to facebooks, twitters or googles login page and the user logs in. I implemented the complete flow but after completing the login I am unable to close the page which I opened.Here is the code snippet.
$scope.twitterLogin = function() {
var loginUrl = $scope.twitterLink;
var socialLoginWindow = window.open(loginUrl, '_blank', 'location=no,toolbar=yes');
socialLoginWindow.addEventListener('loadstart', function (event) {
var url = event.url,
params = {},
// get uri
parts = url.split('?'),
uri,
urlParams,
loading;
console.log(url);
alert(url);
// if there is an uri
if (parts[1]) {
uri = parts[1];
// get uri params
urlParams = uri.split('&');
// get uri params and store them with key, value
angular.forEach(urlParams, function (paramString) {
var param = paramString.split('=');
params[param[0]] = param[1];
});
}
// if there is an email param or an error -> close the window
if (params.email || params.error) {
socialLoginWindow.close();
}
});
};
(the event listener is also not working) After the problem occurred I started with new project where in there was just a button and on ng-click on that button . I called the function below.
$scope.outofwrld = function() {
try {
alert("1");
var loginUrl = "http://www.google.com/"
window.open(loginUrl, '_self', 'location=no,toolbar=yes');
alert("2")
} catch (err) {
alert(err);
}
}
but now the alerts are working well but I cant see the window. I suppose that the window is being opened in the background if so how do I bring it to the foreground and close it. P.S. I am using cordova inappbrowser plugin