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

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

问题描述

动态添加的脚本不会显示在浏览器的调试器脚本部分。
解释:



我需要使用并使用

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

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



但浏览器在调试器脚本部分中没有显示动态加载的myScript.js。有没有人知道任何其他方式,以便所有的目标都可以实现,这将使得能够在浏览器本身中调试动态加载的脚本。



thanx无论如何

解决方案

您可以给动态加载的脚本一个名称,它在Chrome / Firefox JavaScript调试器中显示。为此,您可以在脚本末尾发表评论:

  //#sourceURL = filename.js 

该文件将在来源选项卡中显示为 filename.js 。在我的经验中,您可以使用\的名称,但如果使用/的话,我会得到奇怪的行为。



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


Dynamically added script not showing up in browser's debugger's scripts section. Explaination:

I need to use and have used

if( someCondition == true ){
   $.getScript("myScirpt.js", function() {
       alert('Load Complete');
       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..

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

Does anyone know any other way round so that all of the goals may be achieved which will make one to be able to debug dynamically loaded script there in the browser itself.

thanx anyway

解决方案

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

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.

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

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

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