I have a 2 page application, where one is a parent page which opens the second page using window.open(url).
I am watching for onunload or pagehide event from the child page. Both events are fired for the first time when child page opens(as expected) then when I refresh the child page the events are fired again but after that on close or refresh none of the events are triggered. Here is a sample code:
parent page
const newWindow = window.open(url);
newWindow.onunload = () => console.log('Unload event fired');
newWindow.onpagehide = () => console.log('PageHide event fired');
Both onunload & onpagehide events are recorded till first refresh of the child page. After refresh, If I try to refresh the page again or close the tab none of the event is recorded.
Here I am refreshing the child page which window.open opens. Also the url domain for both parent and child are same.
Am I doing something wrong here?