MyTetra Share
Делитесь знаниями!
Load scripts after page has loaded?
Время создания: 13.07.2018 15:30
Текстовые метки: javascript script load
Раздел: Javascript

In JQuery you could do this on document ready


$.getScript("somescript.js", function(){

alert("Script loaded and executed.");

});


----


It is possible. I was doing a similar thing in an AJAX intensive site, but I was loading the Google Charts API. Here is the code I used to load the Google Charts API when a button was clicked on the page.


function loadGoogleChartsAPI() {

var script = document.createElement("script");

// This script has a callback function that will run when the script has

// finished loading.

script.src = "http://www.google.com/jsapi?callback=loadGraphs";

script.type = "text/javascript";

document.getElementsByTagName("head")[0].appendChild(script);

}


function loadGraphs() {

// Add callback function here.

}


This uses a callback function that will run when the script has loaded.


----


No one mentioned these?


$(window).load(function(){

// do something

});


or


$(window).bind("load", function() {

// do something

});



Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования