[英]console.log doesn't execute within callback but alert() does?
I'm scratching my head rather heavily over this one. 我在这上面挠头。 So I have a JS script that needs to execute after another script so I've injected it into the head with a callback.
因此,我有一个需要在另一个脚本之后执行的JS脚本,因此我已将其注入带有回调的头部。 Here's a snippet of the code that works, it pops up with the alert after loading the initial script.
这是有效的代码片段,在加载初始脚本后,它会与警报一起弹出。
loadBackupScript(function() {
alert('test');
});
But merely changing the alert to console.log (see below) seems to break the functionality, it doesn't throw up any errors, just fails to log anything in the console. 但是仅将警报更改为console.log(请参见下文)似乎会破坏功能,它不会引发任何错误,只是无法在控制台中记录任何内容。 Anything more complex within the anonymous function appears to do the same.
匿名函数中任何更复杂的事情似乎都可以做到。 Any ideas?
有任何想法吗?
loadBackupScript(function() {
console.log('test');
});
Edit: Here's the loadBackupScript function, but I'm certain it's not a problem with this as it executes an alert perfectly fine. 编辑:这是loadBackupScript函数,但是我确定这不是问题,因为它可以很好地执行警报。
function loadBackupScript(callback) {
var script;
if (typeof callback !== 'function') {
throw new Error('Not a valid callback');
}
script = document.createElement('script');
script.onload = callback;
script.src = '/SiteAssets/Kent Normal1.js';
document.head.appendChild(script);
}
我错误地单击了firebug中的日志记录选项,感谢synaps的评论,在进入这里之前应该已经对其进行了真正的测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.