Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:37:59+00:00 2026-06-13T15:37:59+00:00

I have some problems with JavaScript timings..Basically i want it to start timing when

  • 0

I have some problems with JavaScript timings..Basically i want it to start timing when it goes out of focus and when it comes back to focus, the timing will stop and it will display.

var start,end,isTimerOn=0;
window.addEventListener('blur', function() { //when user get out of the screen
/*Start Time when user goes out of focus*/
start = new Date().getTime();
});
window.addEventListener('focus', function() { //when user focus on the screen
if (isTimerOn==1)
{
    end = new Date().getTime();
    var time = end - start; //time will be in ms. eg: 1 sec will be 1000

    /*Convert to seconds*/
    var y=Math.round(time/1000);

    start=0; //reset
    isTimerOn=0; //reset
    alert('Execution time: ' + y  + 'secs'); //this will print the time how long the user has been away

}
});

Now the isTimerOn variable is a flag which will be set when:

function ProcessThisSearch(form)
{
    //alert("OI!"); //test is js is working.
    var test=form.search.value;
    //alert(test); //test if value can be retrieved
    if (test)
    {
        isTimerOn=1;
        window.open('http://www.'+test+'.com');
    }

}

This function ProcessThisSearch(form) will be invoked in the following HTML form:

<form align=right action="mainheader.jsp" method="POST"><input type="text" name="search"><input type="submit" value="Open Website" onClick="ProcessThisSearch(this.form)"></form>

I believe the problem is with the isTimerOn variable. Because I have tested the two event listener and it is working. Only when I add isTimerOn variable, it doesn’t seem to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:38:00+00:00Added an answer on June 13, 2026 at 3:38 pm

    Your HTML code will set isTimerOn=true, only on form submit.
    Probably this is NOT what you want.

    Submitting the form will also change the current page to mainheader.jsp AND load another page by the ProcessThisSearch function.

    The possible fixes would be:

    <button onClick="ProcessThisSearch(this.form)">Open Website</button>

    OR

    <form align=right action="mainheader.jsp" method="POST"><input type="text" name="search"><input type="submit" value="Open Website" onClick="ProcessThisSearch(this.form);return false;"></form>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problems figuring out how to group to certain variables in javascript.
I have some problems with Javascript. In fact, I'm just newbie in that script
I have some problems to start programming using cocos2D on linux + android. I
because of some problems with joomla in-content javascript I have to give all my
Im having some problems with MVC3 and javascript I have a structure with a
I have some problems with JavaScript using ASP.NET 4.0 WebForms Routing. My code: void
I am facing some problems when page is posted back partially. I have some
Im developing a javascript/php/ajax application and have stumbled across some problems. Im confident at
I have some XML which I want to extract via a javascript regular expression.
I have some problems with making Javascript work with Django template inheritance. According to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.