locked
How to disable the settimeout on button click in javascript

    Question

  • Hi,

    I m using settimeout for the tile updates like this.

     setTimeout(function () { document.getElementById("croppingDiv").style.backgroundImage = "URL('/images/images (13).jpg')" }, 2000);
     setTimeout(function () { document.getElementById("croppingDiv").style.backgroundImage = "URL('/images/images (3).jpg')" }, 4000);
     setTimeout(function () { document.getElementById("croppingDiv").style.backgroundImage = "URL('/images/images (13).jpg')" }, 6000);
    setTimeout(function () { document.getElementById("croppingDiv").style.backgroundImage = "URL('/images/images (3).jpg')" }, 8000);    

    But if i click on the button to navigate to next page before 8 second then its generating error. Hot can i disabled this settimeout when the navigation button is pressed. I want help programmatically.

    Thursday, January 10, 2013 7:09 AM

Answers

  • Hi,

    Please using HTML5 Web Worker to do that.

    When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.

    A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.

    #HTML5 Web Workers

    http://www.w3schools.com/html/html5_webworkers.asp


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Wednesday, January 16, 2013 9:33 AM
    Thursday, January 10, 2013 9:13 AM
  • If you are using a PageControlNavigator and set a Timeout, the next page is loaded dinamically but the context in which you created the Timeout still exists. That's why your error occurs.

    You have to clear the timeout when you switch pages and you are using a PageControlNavigator.

    • Marked as answer by Song Tian Wednesday, January 16, 2013 9:33 AM
    Thursday, January 10, 2013 3:53 PM

All replies

  • Hi,

    Please using HTML5 Web Worker to do that.

    When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.

    A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.

    #HTML5 Web Workers

    http://www.w3schools.com/html/html5_webworkers.asp


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Wednesday, January 16, 2013 9:33 AM
    Thursday, January 10, 2013 9:13 AM
  • Hi,

    My settimeout is running in javascript independently . Then why its generating an error if i click on navigation button before 8 seconds.

    It should move to next page without generating an error.


    sulkde

    Thursday, January 10, 2013 10:16 AM
  • If you are using a PageControlNavigator and set a Timeout, the next page is loaded dinamically but the context in which you created the Timeout still exists. That's why your error occurs.

    You have to clear the timeout when you switch pages and you are using a PageControlNavigator.

    • Marked as answer by Song Tian Wednesday, January 16, 2013 9:33 AM
    Thursday, January 10, 2013 3:53 PM
  • Hi,

    I have creates tiles using  ListView .

    Now i wanna to delete an item from the ListView soon after selecting it.

    How can i do that???

    Shilpa Monocept Windows store apps

    Thursday, January 17, 2013 1:41 PM
  • Your ListView should be bound to a DataSource, modifying the DataSource will trigger a One-Way synchronization with the ListView that will update it.

    Just delete the item from the DataSource and it will work.

    Thursday, January 17, 2013 2:24 PM