[英]How do I enable chrome debugging when inserting a script tag into the head using jquery
I came across this case while trying to dynamicly load a bunch of script files, and where I was getting no errors returned when the JavaScript was failing. 我在尝试动态加载一堆脚本文件时遇到了这种情况,并且在JavaScript失败时没有返回任何错误。 This will hopefully save someone a lot of time.
希望这会节省很多时间。
How do I enable chrome debugging when inserting a script tag into the head using jquery. 使用jquery将脚本标签插入头部时,如何启用Chrome调试。 This does not allow for debugging (no errors are returned).
这不允许进行调试(不返回错误)。
$(function(){
$('head').append('<script type="text/javascript" src="example.js"></script>');
});
I found that doing it via standard dom insertion will work. 我发现通过标准dom插入完成此操作将起作用。
. 。 Possibly because jquery picks up what your doing and tries to use ajax instead?
可能是因为jquery接管您的工作并尝试使用ajax代替? this doesnt sound right, but it the only thing I can think of.
这听起来不对,但这是我唯一能想到的。
. 。 Note that it only the $('head').append that causes it to prevent debugging for some reason.
请注意,只有$('head')。append会由于某种原因导致它阻止调试。
function safeAddScript(url){
var el=document.createNode('script');
el.type="text/javascript";
el.src=url;
document.getElementsByTagName('head')[0].appendChild(el);
}
$(function(){
safeAddScript('example.js');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.