Forum Moderators: open
<script type="text/javascript">
//If the time is less than 10,
//you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
var d = new Date();
var time = d.getSeconds();
if (time > 10)
{
alert("Hello day!")
}
</script>
</body>
</html>
Check out: [w3schools.com...] (a very useful website)
So let's apply this to your situation:
<script type="text/javascript">
function showAlert() {
var d = new Date();
var time = d.getSeconds();
if (time > 10)
{
alert("Hello day!")
}
var t = setTimeout("showAlert()",10000) // in milliseconds
}
</script>
<a href="#" onclick="showAlert()">Start loop</a>
When you click, it activates the function. I'm not entirely sure why you want it to loop though...
<script type="text/javascript">
function showAlert() {
var d = new Date();
var time = d.getSeconds();
if (time > 10)
{
alert("Hello day!")
}
}var t = setInterval("showAlert()",10000) // in milliseconds
function stopBotheringMe() {
clearInterval( t);
}
</script>
Also as we have set the interval outside the function it will now start automtically.
If you wanted to you could use stopBotheringMe() to stop the interval.
This seems like a particularly annoying thing to do, do you mind if I ask what it's for?