如何在浏览器的调试器本身中调试动态加载的JavaScript(使用jQuery)? [英] How to debug dynamically loaded JavaScript (with jQuery) in the browser's debugger itself?

查看:207
本文介绍了如何在浏览器的调试器本身中调试动态加载的JavaScript(使用jQuery)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态添加的脚本未显示在浏览器的调试器脚本部分中。

A dynamically-added script is not showing up in the browser's debugger's scripts section.

说明:

我需要使用并使用

if( someCondition == true ){
   $.getScript("myScirpt.js", function() {
       alert('Load Complete');
       myFunction();
   });
}

以便myScript.js可以在满足某些条件时动态加载...
只有在加载完整个脚本后才能调用myFunction ...

so that myScript.js can be dynamically loaded on meeting some condition... And myFunction can be called only after getting the whole script loaded...

但是浏览器没有在调试器的脚本部分显示动态加载的myScript.js 。

But browsers are not showing the dynamically loaded myScript.js in their debugger's script section.

是否有另一种方法可以实现所有目标,这将使人们能够在浏览器本身中调试动态加载的脚本?

Is there another way round so that all of the goals may be achieved which will make one to be able to debug a dynamically-loaded script there in the browser itself?

推荐答案

您可以为动态加载的脚本命名,以便在Chrome / Firefox JavaScript调试器中显示。要执行此操作,请在脚本末尾添加注释:

You can give your dynamically loaded script a name so that it shows in the Chrome/Firefox JavaScript debugger. To do this you place a comment at the end of the script:

//# sourceURL=filename.js

此文件将在来源标签中显示为 filename.js 。根据我的经验,您可以在名称中使用\,但如果使用/,则会出现奇怪的行为。

This file will then show in the "Sources" tab as filename.js. In my experience you can use \'s in the name but I get odd behaviour if using /'s.

有关详细信息,请参阅:
动态JavaScript中的断点
< a href =https://developers.google.com/web/updates/2013/06/sourceMappingURL-and-sourceURL-syntax-changed =noreferrer>弃用// @ sourceurl

For more information see: Breakpoints in Dynamic JavaScript deprecation of //@sourceurl

这篇关于如何在浏览器的调试器本身中调试动态加载的JavaScript(使用jQuery)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆