how to stop the running function ?

Discussion in 'JavaScript' started by mmjanjust, Mar 24, 2010.

  1. #1
    how to stop the running function ?
     
    mmjanjust, Mar 24, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Try return false;
     
    s_ruben, Mar 24, 2010 IP
  3. mmjanjust

    mmjanjust Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    i have try it return false; , but still failed
    any idea ?
     
    mmjanjust, Mar 24, 2010 IP
  4. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can you provide a code snippet of your function so we can see whats going wrong?
     
    Nyu, Mar 24, 2010 IP
  5. mmjanjust

    mmjanjust Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    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):
     
    Last edited: Mar 24, 2010
    mmjanjust, Mar 24, 2010 IP
  6. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #6
    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
     
    Amator, Mar 24, 2010 IP
  7. mmjanjust

    mmjanjust Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    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() ?
     
    mmjanjust, Mar 24, 2010 IP
  8. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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
     
    Nyu, Mar 24, 2010 IP
  9. mmjanjust

    mmjanjust Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    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 ?
     
    mmjanjust, Mar 24, 2010 IP