简体   繁体   English

在Visual Studio 2010中调试JavaScript?

[英]Debug JavaScript in Visual Studio 2010?

Currently I am debugging my JavaScript using Firebug for Firefox. 目前我正在使用Firebug for Firefox调试我的JavaScript。 Is there anyway to debug javascript in Visual Studio 2010? 反正有没有在Visual Studio 2010中调试javascript? The JavaScript isn't part of any Visual Studio project, it's just a .js file that will be linked to a static HTML page (it's to debug school assignments). JavaScript不是任何Visual Studio项目的一部分,它只是一个.js文件,它将链接到静态HTML页面(它用于调试学校作业)。

I did try searching and the results weren't any more recent than around a year ago. 我确实尝试过搜索,结果不是一年前的结果。 I'm hoping something has changed or there is a better workflow than notepad++ for HTML/JavaScript and Firebug for debugging. 我希望有一些东西已经改变,或者有一个比用于HTML / JavaScript和Firebug的notepad ++更好的工作流程来进行调试。

Use the JavaScript debugger keyword in IE. 在IE中使用JavaScript调试器关键字。

function onClickRow(detailUrl) {
    debugger;
}

When run your page in IE, a debug window will pop up, then select Visual Studio 11. 在IE中运行页面时,会弹出一个调试窗口,然后选择Visual Studio 11。

To use debug in Internet Explorer, you need perform these steps: 要在Internet Explorer中使用调试,您需要执行以下步骤:

  • enable script debugging in IE (go to Internet options->advanced->browsing and uncheck 'Disable script debugging') 在IE中启用脚本调试(转到Internet选项 - >高级 - >浏览并取消选中'禁用脚本调试')
  • select view->external script debugger->break on next statement 选择view-> external script debugger-> break on next statement

When next javascript statement will be reached, IE will show standard windows debugger selection dialog, when you can select instance of visual studio. 当下一个javascript语句到达时,IE将显示标准的Windows调试器选择对话框,当您可以选择visual studio的实例时。

Update : With visual studio you can attach to browser process(eg iexplore.exe) and then debug 更新 :使用visual studio,您可以附加到浏览器进程(例如iexplore.exe),然后进行调试

This question gets a lot of views so for the sake of completeness I just wanted to mention that I've been using Chrome Developer Tools for a while now. 这个问题得到了很多观点,所以为了完整起见,我只是想提一下,我一直在使用Chrome开发者工具 It's been working great for me and is what I recommend now when people ask me this same question. 这对我来说很有用,当人们问我同样的问题时,我现在推荐它。

Yes, but only in IE. 是的,但仅限于IE。 Basically just create a web-page project and hit run. 基本上只需创建一个网页项目并点击运行。 It'll launch IE in debugger mode. 它将以调试器模式启动IE。

If you installed VS 2012 and then uninstalled it, you may need to Re-Install Visual Studio 2010. 如果您安装了VS 2012然后将其卸载,则可能需要重新安装Visual Studio 2010。

Error you may get when trying to debug JavaScript: 尝试调试JavaScript时可能会出现错误:

---------------------------
Microsoft Visual Studio
---------------------------
Unable to attach to the crashing process. The correct version of pdm.dll is not registered. Repair your Visual Studio 2010 installation, or run 'regsvr32.exe "%CommonProgramFiles%\Microsoft Shared\VS7Debug\pdm.dll"'.
---------------------------
OK   
---------------------------

如果你想尝试在IE中试一试,我发布了在这里使用js调试器: jQuery / Ajax内容没有出现/在资源管理器中加载

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

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