1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

@HostListner with 'window:beforeunload'

Discussão em 'Angular' iniciado por Sai Pavirala, Junho 17, 2025.

  1. Sai Pavirala

    Sai Pavirala Guest

    I was using the @HostListner ('window:beforeunload') to call a http.get request to when the user was trying to refresh or close browser tab or window.

    @HostListener('window:beforeunload', ['$event'])
    handleBeforeUnload(event: Event) {
    console.log("chat session id ", this.sessionService.getSessionId())

    if (this.sessionService.getSessionId() != null) {
    this.chatService.closeAgent();
    this.sessionService.removeSessionId()
    }
    }

    closeAgent() {
    if((environment.genAIService === 'IG_GENAI_SERVICE')&&(this.sessionService.getSessionId()!=null)){
    const chatSessionId = this.sessionService.getSessionId();
    const url = `va/close-chat/${chatSessionId}`;
    this.http.get<boolean>(url).subscribe({
    next: (response) => {
    console.log('API call successfully ',response);
    //this.tosterService.showInfo("Your session is closed")
    }
    });
    }
    }


    This is working fine in my local with http but it was not working with https sometimes. Can someone please help me to fix this issue. Thanks

    Continue reading...

Compartilhe esta Página