• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

how to disable setInterval after someone clicks a specific link

hi all,
my manager wants me to make function called say x() execute each 4 seconds once after the page load then if specific link clicked no more executing the x function each 4 seconds

I'm newbie to this scenario can any body tell me how to do this scenario in syntax

best regards
hatem gamal
0
hatem_from_mesr
Asked:
hatem_from_mesr
1 Solution
 
DevoneyCommented:
Make a .html file and put this code in their, open the file with your browser.


<html>
<header></head>
 
<SCRIPT LANGUAGE = "JavaScript">
<!--
var secs
var timerID = null
var timerRunning = false
var delay = 1000
 
function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 3
    StopTheClock()
    StartTheTimer()
}
 
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
 
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        alert("You have just wasted 3 seconds of your life.")
	InitializeTimer()
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
//-->
</SCRIPT>
 
 
<body onload="InitializeTimer();">
<a style="cursor:pointer;" onClick="javascript:StopTheClock();" >Stop timer now</a>
</body>
</html>

Open in new window

0
 
hatem_from_mesrAuthor Commented:
thanks man
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now