Click to See Complete Forum and Search --> : turn off Javascript Function with ONCLICK Button


yphasukyued
11-26-2003, 08:11 AM
I have javascript function ONLOAD in <BODY ONLOAD=sample()>. How can I unload or disable this function from BUTTON.

requestcode
11-26-2003, 08:13 AM
What does the function look like? We need to see that to determine if it is possible.

Gollum
11-26-2003, 08:17 AM
It doesn't sound possible.

Either you are trying to disable the onclick handler, using a button that can only be clicked after the body onload handler has completed...

Or you are trying to disable javascript in the browser, which I don't think you can do.

TheBearMay
11-26-2003, 08:28 AM
If the function is in an external JS file, you can create another file with a blank function of the same name and repoint the src of the script statement.

(I'm doing this from memory so bear with me)


<script id='ReplaceableScr' src='LiveScript.js'><script>
<script>
var LiveScr='true';
function ScriptExchange(){
if(LiveScr){
ReplaceableScr.src='DeadScript.js';
LiveScr='false';
SwitchButton.value='Enable Function'}
else {
ReplaceableScr.src='LiveScript.js';
LiveScr='true';
SwitchButton.value='Disable Function'}
</script>
...
<button id='SwitchButton' onclick='ScriptExchange();'>Disable Function</button>...