As an example a user could click a button which fires off a new browser window, the header of the page will cause a download to be triggered. Once the headers have been downloaded the new page will close. Whilst this is going on, the original browser window will be redirecting to a new page.
var newWindow = window.open('http://www.example.com/my-download','_blank'); newWindow.blur(); window.focus();
Lets look at each line:
In line one we are setting a new open window event to the variable newWindow. This will trigger the new window to open. The second parameter in the open event is the target. In this case its set to _blank which means that the new window will open in a new page.
var newWindow = window.open('http://www.example.com/my-download','_blank');
On the second line we all calling the blur method on the newWindow. This forces the new window to lose its focus. – Thus making the new window hidden from view.
The last line calls the focus event on the original window object. This keeps the focus on the current window so the user doesn’t notice the second action.