У меня есть целая куча javascript-файлов, которые нужно загрузить по порядку. Однако один из них не загружается в ie7.Ресурс Javascript не загружается в ie7
Вот функция, которая выполняет загрузку:
function loadScript(url, callback){
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
// Attach handlers for all browsers
var done = false;
script.onload = script.onreadystatechange = function()
{
if(!done && (!this.readyState
|| this.readyState == "loaded"
|| this.readyState == "complete"))
{
done = true;
// Continue your code
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
А функция вызывает:
loadScript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',function(){
loadScript('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js',function(){
loadScript('http://XXX/js/data.php?rand='+Math.random(),function(){
loadScript('http://XXX/js/jquery.inject.js?rand='+Math.random(),function(){
console.log('a');
loadScript('XXX/js/press.js?rand='+Math.random(),function(){
console.log('b');
inject_press();
});
});
});
});
});
Файл, который не нагружает я jquery.inject.js, чей код
console.log('y');
jQuery.prototype.inject = function(a){
...
}
Снова это работает во всех браузерах кроме ie7. Выходной сигнал
a
b
http://blog.andrewcantino.com/blog/2008/11/23/replacement-for-script-onload-in-ie/ – McGarnagle
Нагрузочные устройства срабатывают, а не console.log() s для 'a 'и' b ', которые заправлены в комплект callbacka –