Prindol

DESIGN, HTML5, CSS3, DOM, Jquery, JSON, Actionscript2/3, Linux, IIS

You are not logged in.

#1 2017-11-17 15:23:26

skydown
Administrator
Registered: 2011-07-25
Posts: 315

[JAVASCRIPT] loadScript 콜백지원

- .js 로드 완료후 함수 실행

if(typeof jQuery == 'undefined') {
	loadScript('/js/jquery-1.10.1.min.js', function () {
		// .js가 로딩 완료한 시점에 실행
		init();
	});
} else {
	init();
}

function loadScript(src, callback) {
	var script = document.createElement('script'),
		loaded;
	script.setAttribute('src', src);
	if (callback) {
		script.onreadystatechange = script.onload = function() {
			if (!loaded) {
				callback();
			}
			loaded = true;
		};
	}
	document.getElementsByTagName('head')[0].appendChild(script);
}

Offline

Board footer

Powered by FluxBB