Search code examples
javascriptwebpolymer

Are there any alternatives to 'window.onload' in polymer?


I am trying to trigger a setTimeout using window.onload, but unable to do so. Are there any other ways to do this?

    window.onload =  function() {
        setTimeout(function(){ 
            alert('Hide that spinner!'); 
        }, 3000);
        console.log('After 3 seconds');
    };

Solution

  • As you are using Polymer 1, you can use ready callback function:

    ready: function(){
        setTimeout(function(){ 
            alert('Hide that spinner!'); 
        }, 3000);
        console.log('After 3 seconds');
      }
    

    It is called after property values are set and local DOM is initialized.