How to debug JAVASCRIPT events? Or how to make all functions call trace?

馋奶兔 提交于 2019-11-28 21:15:40

问题


For example there is a button. It is wrapped by <div>.

When pressing to this button, there is javascript function call happen, then another function, then calling by ajax to the server and if it's OK, javascript redirecting this page to another page.

It's hard to debug.

Is it possible to "catch" this event? I.e. to know, what function is called after the click on the button? Button doesn't have attribute "onclick" i.e. event listener is connected in javascript.

And if it's not possible then is it possible to make trace? That is to look at all functions calls, which is called after which?

It would be better in visual way, though in textual is also good:)

Thanks for replies!


回答1:


Yeah - this sort of thing is not as simple is you would like.

Google Chrome has an Event Listeners panel. Right-click your button, then select Inspect Element. Make sure the correct element is selected, then check the Event Listeners panel on the right.

You can also use the debugger keyword to set a breakpoint in the call stack somewhere. Then use your favorite javascript debugger (built-in dev tools in Safari, Google Chrome & IE8, firebug for Firefox). In each of these, there's a call stack that'll allow you to navigate through the current call stack.




回答2:


You can use firebug to trace the javascript code. Its plugin of Firefox to trace the styles (css), js and also allows to edit.

Opera provides dragonfly which is similar to firebug




回答3:


Check out the debugging features in Firebug, it'll let you add JavaScript breakpoints and step through your code.



来源:https://stackoverflow.com/questions/3509032/how-to-debug-javascript-events-or-how-to-make-all-functions-call-trace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!