how to calculate popup window timing

HI ,

I have  course link , if i press any course then one popup will open , that time i want to calculate the timing how much time the popup window is open ?  how to do that ??
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could try to launch a function when opening the popup through a setInterval of 1 milisecond. That function will check if the popup window exists and, if it isn't, increase a miliseconds counter.

Problems with this idea:
-Executing a function each milisecond, although a simple one like this, is not a good idea for performance.
-Also the execution of the own function will delay the counter, under client computer load maybe even one call to the function may arise before the last one finishes.

I don't understand why do you want to control this. A pop-up opening will be always called in the less time possible and it will be dependant on the client machine load and capabilities, so seems quite pointless to me to measure this time.
Easwaran ParamasivamCommented:
Have var starttime and endtime globally declared.

In the document.onload method set the current time to starttime.

In the window.onbeforeunload method have a function. In that function set the current time to endtime. Find the time difference (endtime - starttime). This is the duration to calculate the open time of the window.

Sathish David Kumar NArchitectAuthor Commented:
Can ypu give some sample code??
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Easwaran ParamasivamCommented:
At start of your <script> tag

 var startdate, enddate;

document.onload = loadfunction();
window.onbeforeunload = unloadme();

function loadfunction()
startdate = new Date();

function unloadme()
 enddate= new Date();

 //calculate difference b/w enddate and startdate. Refer the below link for that.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sathish David Kumar NArchitectAuthor Commented:
@EaswaranP: i am asking for popup winodow time calulcation

The Main in the question is

1. Calculate time how much time the popup is open ?
Easwaran ParamasivamCommented:
Thats what my answer for. Have you tried that? What are you getting?
Sathish David Kumar NArchitectAuthor Commented:
Not get full solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.