How do I dump JavaScript vars in IE8?

2019-01-10 06:38发布

I have an object I need to examine in IE8. I tried the developer tools and console.log, their Firebug equivalent. However, when I output the object to the log:

console.log("Element: ", element);
console.log(element);

I only get the string

LOG: Element: [object Object]

instead of a clickable, examinable dump.

Is it possible to dump an object to the Log and examine its members, like in Firebug?

I can't use a homemade dump() function because the element I want to examine is so huge the browser will crash on me.

11条回答
叼着烟拽天下
2楼-- · 2019-01-10 06:42

If you're dealing with nasty code and console.log is not available, try this in the console:

out = []; for (i in your_object) { out.push(i) } out.join("\n")
查看更多
神经病院院长
3楼-- · 2019-01-10 06:45

@Chris commented @Andy's answer with the simple solution: Use console.dir(myObj) to get all the details printed out in the console in IE. Thanks Chris!

查看更多
相关推荐>>
4楼-- · 2019-01-10 06:52

Add this Tag in your page :

<script type="text/javascript" src="https://getfirebug.com/firebug-lite-debug.js"></script>

And the things will work.

Its working on my system.

Note: Do try this solution.

查看更多
叼着烟拽天下
5楼-- · 2019-01-10 06:52

A pictorial version of Xavi's excellent answer:

enter image description here

查看更多
仙女界的扛把子
6楼-- · 2019-01-10 06:56

Here's one technique that I've found helpful:

  • Open the Developer Tool Bar (hit F12)
  • Go to the "Script" tab
  • Click the "Start Debugging" button
  • Next, type "debugger" into the console and hit enter. This should trigger a break point.
  • Go to the "Watch" sub-tab
  • Click the row that says, "Click to add..." and enter a variable you'd like to examine. Note that the variable must be globally available.
  • At this point you should be able to examine your variable with tree-like UI
  • Once you're done debugging click Continue button (or hit F5)
查看更多
男人必须洒脱
7楼-- · 2019-01-10 06:57

console.log(element.toString()) might be your friend here...

查看更多
登录 后发表回答