View Full Version : How can I make a script function disabled ??

06-09-2007, 04:22 PM
I want to use a hyperlinked text, linked with a script function that makes stoping functioning another script.
Can you help me ?

06-09-2007, 04:52 PM
It really depends on that 'another script' that you want to stop. A script can be stopped in a number of ways, some none too graceful. If you redefine one of its global variables to be out of range of what is expected or if you redefine one of its key functions, this should stop it, but often with errors and/or (depending upon what the script does) odd visual or other effects.

If the script loops (via timeout) or reacts to events, you can often place a test into it:

function mainFunc(){
if (mainFunc.stop)
do whatever this script does

Then your link to stop it could be:

<a href="#" onclick="mainFunc.stop=true;return false;">Stop</a>

If it loops via interval, you may need to clear the interval as well, and this is usually a good idea anyway where intervals are involved and the script needs to stop. Sometimes, even if it loops via timeout, that needs to be cleared too. To be more specific, I would need to see more details on the actual setup, preferably a link to the live page.