Form in iframe unable to regain focus with Angular and IE11
I have no idea what causes this issue, probably IE quirk.Anyway, I found that it works just fine if you focus the iframe manually in JS but it must be in a $timeout
.
I added an ng-init to the iframe that basically focuses the iframe manually.
.state('iFrame/:flag', { url:'/iframe/:flag', template: '<h4>Iframe</h4><p><iframe src="{{vm.url}}" ng-init="vm.init()" id="iframeID" frameborder="1" width="100%" scrolling="no"></iframe></p>', controller: 'IFrameCtrlAs', controllerAs: 'vm' });
And here's the controller
function IFrameCtrlAs($stateParams, $location, $timeout) { var vm = this; if(!angular.isDefined($stateParams.flag)){ var reloadPath = $location.path() + '/true'; $location.path(reloadPath); } else{ vm.url = 'form.html'; } vm.init = function(){ $timeout(function(){ document.getElementById("iframeID").contentWindow.focus(); console.log("loaded") }) }}
Of course, it might be cleaner to wrap this in a directive.