Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load JavaScript after page is fully rendered

I've added JavaScript code to my Drupal 7 theme, but it fail to run as it's expected because css are not properly applied when my function is fired.
So I've tried a minimal implementation to check what's happening.

    jQuery(document).ready(function($) {

         alert("Start");  

    }

alert() is fired before the page is fully loaded (i.e. all titles are missing). How can I prevent this?

like image 763
pasine Avatar asked Dec 10 '22 09:12

pasine


1 Answers

In order execute a script after everything has fully loaded you want:

$(window).load(function(){
  alert('hello');
});

jQuery.ready() executes as soon as the DOM is ready, which is usually before external resources have loaded.

like image 122
Alex Weber Avatar answered Dec 15 '22 01:12

Alex Weber