I have a login form that is popped up as a separate browser window. Once the API validates that the user is logged in, how do I close that login browser window in AngularJS?
Asked
Active
Viewed 3.9k times
2 Answers
17
Use $window.close()
in $window service.
You can broadcast the result to another controller like this AngularJS – Communicating Between Controllers

dohaivu
- 2,038
- 15
- 17
-
2in angular modal bootstrap. it says :"Scripts may close only the windows that were opened by it." – Silvio Troia May 02 '14 at 09:26
-
Silvio try use this style of injection: .controller('LoginCtrl', function($scope,$window, $modalInstance) { ... } instead of .controller('LoginCtrl', ['$scope', ''$window', function($scope, $window, $modalInstance) { ... }]); – vladymy Sep 25 '15 at 12:21
-
Please have a look on this thread :- http://stackoverflow.com/questions/34367921/close-window-in-angularjs-on-specific-url-angularjs/34368304#34368304 – user2028 Dec 19 '15 at 11:05
-
Hello dohaivu , can you please tell me that is there any way to track url of window, so that i can close the window on that specific url. – user2028 Dec 19 '15 at 11:50
3
This will first prompt the user, asking them whether they want to close their browser:
$window.close()
You'll want to inject the $window
service into your controller/service. You can also use the global javascript variable window directly, but I prefer to do it the "angular" way and only use injectables.

Community
- 1
- 1

Chris Montgomery
- 2,344
- 2
- 19
- 30
-
@ChrisMontgomery this function is not working any more . It gives an error in Chrome "$window.close is not a function" – Mateen Kadwaikar May 18 '15 at 14:03
-
newWindow.close() worked for me in Chrome 52 when newWindow was a reference to a new tab/window that I had opened with: var newWindow = $window.open(); – SpaceManGalaxy Sep 06 '16 at 18:57