简体   繁体   English

如何在Visual Studio 2013中调试JavaScript

[英]How to debug javascript in Visual Studio 2013

We are trying to build a Windows 8 native application using JavaScript. 我们正在尝试使用JavaScript构建Windows 8本机应用程序。 We are using jQuery to dynamically load the javascripts files, and all the javascript files are stored inside of the app. 我们使用jQuery动态加载javascripts文件,并且所有javascript文件都存储在应用程序内部。 When I try to debug the javascript, the breakpoint can't hit, saying "The breakpoint will not currently be hit....", but in the Solution Explorer, there is a Script Documents project, there is a file called "script block", which contains all the javascripts which are loaded from jQuery. 当我尝试调试javascript时,无法打断点,说“当前不会打断点...。”,但是在解决方案资源管理器中,有一个“脚本文档”项目,有一个名为“脚本”的文件。区块”,其中包含从jQuery加载的所有JavaScript。 I can debug from there after I disable the "Enable Just My Code", but it's difficult to find the right place to put breakpoint, since this file is huge... 禁用“启用我的代码”后,我可以从那里进行调试,但是由于该文件很大,因此很难找到放置断点的正确位置。

Actually all the javascript files are having sourcemap attribute, for example: //# sourceURL=ms-appx://d664ef20-6ac8-11e4-ab78-2f4dc8b50d53/www/resources/abc.js 实际上,所有的javascript文件都具有sourcemap属性,例如://#sourceURL = ms-appx://d664ef20-6ac8-11e4-ab78-2f4dc8b50d53/www/resources/abc.js

It is working fine with all the browsers, IE, Safari, Firefox and Chrome. 它可以与所有浏览器(IE,Safari,Firefox和Chrome)正常工作。 But Visual Studio seems not be able to recognize them. 但是Visual Studio似乎无法识别它们。

Anyone who has the same issue? 有人遇到同样的问题吗?

Regards, Xiaojun 祝小军

I expect you are doing this, which evals the contents as a string, causing the string to be added to the "eval code" file under Script Documents. 我希望您正在执行此操作,该操作将内容评估为字符串,从而将该字符串添加到“脚本文档”下的“评估代码”文件中。 Note, you can still set breakpoints, you just have to do it from the "eval code" document. 注意,您仍然可以设置断点,只需从“评估代码”文档中进行设置即可。

// eval via AJAX -- adds to the "eval code" document
$.ajax("./js/fileToAdd.js").done(function (data) {
    window.eval(data);
});

If you load the file via a script tag, the script file is loaded separately and breakpoints bind as expected because the contents are tied to the file and not a string. 如果通过脚本标签加载文件,则脚本文件将单独加载,并且断点将按预期方式绑定,因为内容绑定到文件而不是字符串。 Here's how: 这是如何做:

// Add <script> tag to head -- Causes script file to be loaded/displayed individually
var scriptTag = document.createElement("script");
scriptTag.src =  "./js/fileToAdd.js"
document.head.appendChild(scriptTag);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM