I'm struggling with this problem for a while, so maybe someone will be able to help.
In my Angular project I have a dialog in my login component which opens a new popup window. After successful login this window is closing and following function is triggered:
loginWindow.onbeforeunload = (e) => {
this.dialogRef.close()
}
And here comes the problem because dialog is still opened but I just need to click anything on the screen( even the dialog itself ) and dialog disappears.
I tried to first set focus on this window and then trigger close function but effect is still the same. Using closeAll() gives similar result.
Thanks for any help:)
EDIT:
Here's my component code:
import { Component, OnInit } from '@angular/core';
import { MatDialog, MatDialogRef, MatDialogConfig } from '@angular/material/dialog';
@Component({
selector: 'app-login-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.scss']
})
export class LoginPageComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<LoginPageComponent>
) { }
//some other functions
close() {
this.dialogRef.close();
}
newWindow() {
const loginWindow = window.open(popupWindowUrl,"_blank","height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
loginWindow.onbeforeunload = (e) => {
this.dialogRef.close();
}
}
}