php – How to broadcast event over Web Sockets in JavaScript when user is closing the browser tab/windows in JavaScript-ThrowExceptions

Exception or error:

I have two different web pages that communicate with each other through web sockets.
When user closes one web page (browser tab/window), I want to notify another page by broadcasting event through the web sockets.

But I cannot use window.addEventListener("beforeunload", () => {}) or window.addEventListener("unload", () => {}), because the connection with the web sockets has already been closed when user clicks on the x on the browser tab.

Is there any way or technique to nodify a page when user closes another page? I am working with PHP and JavaScript.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *