javascript 如何在 IE Developer Tools 中为加载时运行的代码创建断点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6931366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:23:11  来源:igfitidea点击:

How do you create breakpoints in IE Developer Tools for code that runs while loading?

javascriptinternet-explorerdebugging

提问by entonio

So I have this web page I need to debug in IE (9). I'd like to use the Developer Tools. I need to create a breakpoint inside code that runs while the page is loading.

所以我有这个网页我需要在 IE (9) 中调试。我想使用开发者工具。我需要在页面加载时运行的代码中创建一个断点。

The problem is that even if I set a breakpoint, when I reload the page it will be erased, as this is a new context.

问题是,即使我设置了断点,当我重新加载页面时,它也会被擦除,因为这是一个新的上下文。

If said code only ran after some given action, I could create the breakpoint and only trigger the action afterwards. But it runs while loading, so no luck.

如果所述代码仅在某个给定操作后运行,我可以创建断点并仅在之后触发该操作。但它在加载时运行,所以没有运气。

The debugger;statement could do what I want, but it triggers the VS Debug with... dialog, in which the only option is VS.

debugger;语句可以执行我想要的操作,但它会触发 VS Debug with... 对话框,其中唯一的选项是 VS。

Thank you.

谢谢你。

回答by Hector Villarreal

I've been doing this for quite a bit, here is the procedure I follow:

我已经这样做了很长时间,这是我遵循的程序:

  1. Put your debugger;line wherever you need it to be in your javascript code.
  2. Open up IE and BEFOREloading your page and press F12 to bring up the Dev Tools
  3. In the Dev Tools, click on the Script tab and press the Start Debuggingbutton. This will make the Dev tools aware of any breakpoints you have specified.
  4. Load up your webpage and the Dev Tool should pick up the debugger statement.
  1. 将您的debugger;行放在您的 javascript 代码中您需要的任何位置。
  2. 加载页面之前打开 IE并按 F12 以调出开发工具
  3. 在开发工具中,单击脚本选项卡并按下Start Debugging按钮。这将使开发工具知道您指定的任何断点。
  4. 加载您的网页,开发工具应该会选择调试器语句。

Good luck!

祝你好运!