1

I am downloading a text file from server.
I want to execute the next command once the file has been downloaded.

I am doing this :

 window.open(location.pathname+'api/generateFile','_blank');
 $scope.searchBls();

Is there a way to make sure that $scope.searchBls() is called only once window.open has finished?

Thanks

user1260928
  • 3,269
  • 9
  • 59
  • 105
  • possible duplicate of [Waiting for child window loading to complete](http://stackoverflow.com/questions/1372022/waiting-for-child-window-loading-to-complete) – Hacketo Aug 17 '15 at 09:43
  • 1
    Subtle difference: _"I want to execute the next command once the file has been downloaded."_ – sdgluck Aug 17 '15 at 09:45

2 Answers2

1

Bind to the window.onload event

var win = window.open(location.pathname+'api/generateFile','_blank');
win.onload = function() {
    $scope.searchBls();
};
Dal Hundal
  • 3,234
  • 16
  • 21
0

Quite simple: window.open

var win = window.open(location.pathname+'api/generateFile','_blank');
win.onload = $scope.searchBls;

You might want to handle the case where the popup has been blocked. In that case win will be undefined

Chris Charles
  • 4,406
  • 17
  • 31