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

2
  • possible duplicate of Waiting for child window loading to complete Commented Aug 17, 2015 at 9:43
  • 1
    Subtle difference: "I want to execute the next command once the file has been downloaded." Commented Aug 17, 2015 at 9:45

2 Answers 2

1

Bind to the window.onload event

var win = window.open(location.pathname+'api/generateFile','_blank');
win.onload = function() {
    $scope.searchBls();
};
Sign up to request clarification or add additional context in comments.

1 Comment

win = window.open opens a new tab and asks me to save the file but $scope.searchBls() is not called.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.