{"action":"closed","issue":{"url":"https://api.github.com/repos/angular-ui/bootstrap/issues/3639","labels_url":"https://api.github.com/repos/angular-ui/bootstrap/issues/3639/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/bootstrap/issues/3639/comments","events_url":"https://api.github.com/repos/angular-ui/bootstrap/issues/3639/events","html_url":"https://github.com/angular-ui/bootstrap/issues/3639","id":73961427,"number":3639,"title":"Modal close fails in IE if modal was opened from js","user":{"login":"Hjertaas","id":5535999,"avatar_url":"https://avatars.githubusercontent.com/u/5535999?v=3","gravatar_id":"","url":"https://api.github.com/users/Hjertaas","html_url":"https://github.com/Hjertaas","followers_url":"https://api.github.com/users/Hjertaas/followers","following_url":"https://api.github.com/users/Hjertaas/following{/other_user}","gists_url":"https://api.github.com/users/Hjertaas/gists{/gist_id}","starred_url":"https://api.github.com/users/Hjertaas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hjertaas/subscriptions","organizations_url":"https://api.github.com/users/Hjertaas/orgs","repos_url":"https://api.github.com/users/Hjertaas/repos","events_url":"https://api.github.com/users/Hjertaas/events{/privacy}","received_events_url":"https://api.github.com/users/Hjertaas/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-07T12:06:46Z","updated_at":"2015-05-07T12:08:44Z","closed_at":"2015-05-07T12:08:44Z","body":"See stacktrace at the bottom.\r\n\r\nUsing angular: 1.4.0-beta.5 and angular-bootstrap: 0.13.0\r\nError seen on IE 9 and 11 (others not tested)\r\n\r\nIf modal dialog is initiated from javascript (say an Angular controller) there is no activeElement\r\nSee line 2209 in ui-bootstrap-tpls.js\r\nvar modalOpener = $document[0].activeElement;   // in IE this is undefined\r\n\r\nThis in turn results in a nullpointer in close() and dismiss() functions. Lines 2262 and 2273 respectively.\r\n\r\nWe are temporarily rectifying this by running this \r\nif (!window.document.activeElement) {\r\n    window.document.body.focus();\r\n}\r\nimmediately prior to calling $modal.open()\r\n\r\nTypeError: Unable to get property 'focus' of undefined or null reference\r\n   at $modalStack.close (http://localhost:9000/ext/angular-bootstrap/ui-bootstrap-tpls.js:2262:11)\r\n   at modalInstance.close (http://localhost:9000/ext/angular-bootstrap/ui-bootstrap-tpls.js:2340:17)\r\n   at fn (Function code:2:191)\r\n   at callback (http://localhost:9000/ext/angular/angular.js:22335:17)\r\n   at Scope.prototype.$eval (http://localhost:9000/ext/angular/angular.js:15236:9)\r\n   at Scope.prototype.$apply (http://localhost:9000/ext/angular/angular.js:15335:11)\r\n   at Anonymous function (http://localhost:9000/ext/angular/angular.js:22340:17)\r\n   at jQuery.event.dispatch (http://localhost:9000/ext/jquery/dist/jquery.js:4664:6)\r\n   at elemData.handle (http://localhost:9000/ext/jquery/dist/jquery.js:4332:5)\r\n   at jQuery.event.dispatch (https://example.com/plugins.3619bc3f.js:3:14958)\r\n   at elemData.handle (https://example.com/plugins.3619bc3f.js:3:9674)"}}