I'm opening an external page in my web app using window.open
and added a addEventListner
for unload
to capture window close. In the unload
event block I want to perform some action and then redirect to another page.
I'm able to open a new tab but as soon the tab is opened the listener code inside the unload
block also get triggered. I want to trigger that code only after the window is closed.
HTML:
<button type="button" (click)="goToUrl('https://mywebsite.com')">Click me!</button>
Component:
verifyWindow: any;
goToUrl(url: string): void {
this.loading = true;
this.verifyWindow = window.open(url, '_blank', 'height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
this.verifyWindow.addEventListener('unload', () => {
this.userInfoService.accountInfo = {
firstName: 'fname',
lastName: 'lname',
userName: 'uname',
email: this.userInfo.email
}
this.router.navigateByUrl('register')
});
}