简体   繁体   English

使用jquery将脚本标签插入头部时,如何启用Chrome调试

[英]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.

相关问题 如何在head标签的顶部/开头插入script标签? - How do I insert a script tag in to the top/beginning of head tag? 通过jQuery追加脚本时我需要setTimeout吗? - do I need setTimeout when appending script to head via jQuery? 使用Firefox时如何在Visual Studio 2008中启用脚本调试 - how to enable script debugging in visual studio 2008 when using Firefox 如何将jQuery脚本附加到head标签 - How to append a jQuery script to head tag 如何在带有 Chrome 调试的 VS Code 中启用文件的可编辑调试? - How do I enable editable debugging of files within VS Code w/ Chrome Debugging? 如何将脚本添加到<head>使用javascript标记 - How to add script to <head> tag using javascript 在Visual Studio 11中使用Chrome启用脚本调试 - enable script debugging using Chrome in Visual Studio 11 如何在里面添加某些脚本标签<head>和<body>使用 HtmlWebackPlugin 时的标签 - How do I add certain script tags inside <head> and <body> tags when using HtmlWebackPlugin 如何使用jQuery在HTML中启用或禁用选择标签? - How do you enable or disable a select tag in html using jQuery? 如何使用jquery / javascript从头部动态添加的脚本标签读取值 - How to read the values from the dynamically added script tag in head using jquery / javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM