Avatar of alcani
 asked on

Javascript timer

Hi experts,

I’m looking for a simple way to set a JavaScript timer to pull content from the server session every few minutes to keep the session active only while the browser window remains open.

Thanks for your comments,

Avatar of undefined
Last Comment
Kyle Hamilton

8/22/2022 - Mon
Kyle Hamilton

look into setInterval
Roopesh Reddy


The example at w3schools isn't what I'd use. They pass a String reference to a function in the setInterval call - I'd do it like this:
<input type="text" id="clock" />
<script type="text/javascript">
var int=window.setInterval(
var d=new Date();
var t=d.toLocaleTimeString();
<button onclick="int=window.clearInterval(int)">Stop</button>

Open in new window

Why, you ask? Because passing a String of code - or function name - to either setTimeout or setInterval is tantamount to using the evil eval statement.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

Thanks for your comments,

In fact I would like to every 9 minutes execute a function call “Submit”

Could you help me with the syntax?
Kyle Hamilton

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question