2

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();
    }
  }

}
Michał B
  • 339
  • 1
  • 3
  • 12

1 Answers1

0

Can you share some code ?

How to you close your dialog ? Are you keeping a ref to your dialog ? If so can you close it with dialogRef.close();

Edit: Maybe this can help you out - What are the limitation using before unload event?

Try wrap your code inside a timeout

Nissan
  • 11
  • 2
  • I add some code in my question. I'm also using antoher dialogs and all works just fine except this one with popup window. – Michał B May 26 '21 at 21:23
  • Unfortunately, this didn't help. I think it might have something to do with parent window losing focus. Even when I was clicking right mouse button anywhere, this dialog disappears. – Michał B May 26 '21 at 23:38