it my part of my code,i am using "window.setTimeout("Start.onLoad()",1);" to start the function , and when close window will call window.onunload = onunload_handler; then stop Start.onLoad() , but when i close window ,i only see the pop-up msg "bye bye" and the method didn't stop , what's wrong with my code ? var Start= { count: 0, onLoad : function () { //when windows running first ,the function will start var myClass = loader.loadClass('com.example.myClass'); var myObj = myClass.newInstance(); var binval = myObj.myMethod(arg1, arg2); }, stoponLoad: function() { this.count++; if (typeof(this.onLoad) == "function") { this.onLoad = null; // destroy method alert('destroy method'); } alert("this is our " + this.count + " run"); } }; window.setTimeout("Start.onLoad()",1); window.onunload = onunload_handler; function onunload_handler(){ Start.stoponLoad(); var warning="bye bye"; alert(warning); } Code (markup):
Sorry, I am not sure if I understand you well. Do you try to stop the timer that you started with setTimeout() ? To do this you need to use the method clearTimeout() . You can find more info on http://www.w3schools.com/js/js_timing.asp
actually, i want to stop the function "Start.stoponLoad();" and i have using clearTimeout(); it's still can stop it . Then I try to start the function using window.addEventListener('load', function () {Start.stoponLoad();}, false); then how to stop the function Start.stoponLoad() ?
Why do you want to stop the function? It gets executed once upon the onunload event and runs the code and it contains and thats all... The function stops itself after that as it reached the end of its containing code
because the function is call other program that is don't stop itself, the program have to depend the javascript to stop . so i have to stop the function in javascript. any idea ?