3

I want to calculate the time spend on the opened browser window from the parent window. the newly opened window is a youtube video or any other external website which we can't do any server-side coding.

 function loadvideo(url , id){
  var a = window.open(url);
  a.onbeforeunload = function() {
    a.console.log("hi");
            }

 }

I want to trigger an event when the window is closed. I tried this. it won't trigger when closing a loaded site.

Manu Varghese
  • 791
  • 8
  • 25
  • It's not clear by your description, what you want is (a) a parent window tracking how long a child window/tab stays open, or (b) you want the child window to be able to record and report how long the parent window has been open? – edo9k Oct 29 '20 at 00:28
  • In any case, you'll need to use the "beforeunload" event, and date/time functions to record the moment the page was opened and the moment it's about to close. These topics will help you on that: 1. [date/time functions](https://superuser.com/a/1292059/453576) 2. [beforeunload event](https://stackoverflow.com/a/1632004/4645909) – edo9k Oct 29 '20 at 00:32

0 Answers0