Object window cleared on $ Interval

I experience rather strange behavior when trying to register the window object defined by $window.open() in AngularJS in $interval

 self = this $scope.childWindow = $window.open(authService.buildAuthorizeUrl(), '_blank') console.log $scope.childWindow var1 = "I may not work" self.var2 = 'I should work' privateData.authInterval = $interval -> console.log $scope.childWindow console.log var1 console.log self.var2 , 1000 

Exit

 Window {document: document, window: Window, frameElement: null, clientInformation: Navigator, onhashchange: nullโ€ฆ} Window {} I may not work I should work Window {} I may not work I should work 

As you can see, the first console.log $scope.childWindow displays a fully qualified window object. All the rest, inside $interval , are output only {} . I tried not to attach childWindow to the $scope object, and I tried to attach it to self . I also tried the following this example and experienced the same behavior. Does anyone know why this is happening? Many thanks.

JSFiddle demo: http://jsfiddle.net/U3pVM/15124/

+5
source share
2 answers

I found out that this should not work in the browser due to security reasons, which may explain why it is โ€œoverwrittenโ€. A case of using this was actually in the Blackberry10 Cordova application. To fix this, you should disable web security in config.xml as follows:

 <access origin="*"/> <preference name="websecurity" value="disable" /> 

Of course * will whiten all domains. To reduce security a bit, add the domains you want to whitelist.

0
source

I tried my code in a browser and setting the debugging point inside the $ interval function, an empty object is registered in the console, but the clock controller on the right shows that $ scope.childWindow is not empty. That way you can just use $ scope.childWindow.

enter image description here

+1
source

All Articles