Rakesh Sabbani
Rakesh Sabbani

Reputation: 1735

How to check if a JS file is finished loading?

I need to enable a button when a JS file is finished loading. The JS file which I am using is a builder from WebSphere Portlet Factory (WPF). How can I check if the JS file is finished loading so that I can enable the button?

Upvotes: 0

Views: 1147

Answers (2)

Siva Charan
Siva Charan

Reputation: 18064

Use JQuery,

$(document).ready(function() {
  // Handler for .ready() called.
});

and Other way

// most browsers
scriptVar.onload = oCallback;

// IE 6 & 7
scriptVar.onreadystatechange = function() {
    if (this.readyState == 'complete') {
        oCallback();
    }
}

Upvotes: 0

Michael Lorton
Michael Lorton

Reputation: 44386

How are you loading the file? If it's an ordinary <script> tag, the next Javascript file will not be run until all previous files have finished loading or died trying.

Other techniques (like $.ajax) have explicit provisions for completion callbacks.

Upvotes: 2

Related Questions