Click here to Skip to main content
15,898,826 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<script>

var target = new Date();
target.setHours(9, 30, 0, 0);
function timer() {
var now = new Date();
if (target.getHours() == now.getHours() && target.getMinutes() == now.getMinutes()) {
alert('9.30am task');
// your code for button click
}
else {
setTimeout(timer, 1000)
}
}

timer();
alert('timer started');

</script>

What I have tried:

sir, this code is working properly auto click at sharp 9.30am, but

how i do auto click button sharp at 9.30am without "timer" function , only needed coding
Posted
Updated 24-May-16 2:46am
Comments
Karthik_Mahalingam 24-May-16 8:05am    
timer is just a function name, you can rename it.
Member 11663301 24-May-16 8:14am    
sir, i understood timer is function name, but
every time needs function excute , i want without function excute auto click button
Karthik_Mahalingam 24-May-16 8:20am    
This is how settimeout works
Member 11663301 24-May-16 8:39am    
sir, it needs to excute timer(); , my request is without excute function 'timer'
only needed code ,
like my thuoght:
var target = new Date();
target.setHours(09, 30, 0, 0);

var now = new Date();
if (target.getHours() == now.getHours() && target.getMinutes() == now.getMinutes()) {

window.open("http://www.mysite.co.in");
// your code for button click
}
Member 11663301 24-May-16 8:47am    
thank u sir , for ur guidelines

Think about what you are asking.

You want the application to do something at a certain time.
It needs to know the time to do this.
You saying you don't want it to check the time.
So how can it know the time without checking?

If this is eating up too much CPU resource, check less often. How accurate do you have to be? Instead of checking every second, why not check every minute? If it needs to be "right on the dot", check the time and start the timer function "on the dot" and then fall back to every minute.

But you cannot do something by the clock without looking at the clock in some way.

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900