如何在 IE8 中转储 JavaScript 变量?
我有一个需要在 IE8 中检查的对象。 我尝试了开发人员工具和console.log(它们的Firebug 等效工具)。 但是,当我将对象输出到日志时:
console.log("Element: ", element);
console.log(element);
我只得到字符串
LOG: Element: [object Object]
,而不是可点击、可检查的转储。
是否可以将对象转储到日志并检查其成员,就像在 Firebug 中一样?
我无法使用自制的 dump() 函数,因为我要检查的元素太大,浏览器会崩溃。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
这是我发现有用的一项技术:
Here's one technique that I've found helpful:
有点偏离主题(因为它不适用于 DOM 元素),但我发现使用 JSON.stringify(object) 获取对象的 JSON 字符串,该字符串非常可读。
A bit off topic (as it won't work for DOM elements) but I've found it handy to use the JSON.stringify(object) to get a JSON string for the object which is pretty readable.
@Chris 用简单的解决方案评论了 @Andy 的答案:使用
console.dir(myObj)
在 IE 的控制台中打印出所有详细信息。谢谢克里斯!@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!如果您正在处理令人讨厌的代码并且 console.log 不可用,请在控制台中尝试以下操作:
If you're dealing with nasty code and console.log is not available, try this in the console:
一种建议是使用 Firebug-Lite:
它包装了控制台 obj,您可以像大多数 Firebug 控制台一样在 IE 中看到结果。
希望这有帮助。
One suggestion is to use Firebug-Lite:
It wraps console obj and you can see the result in IE like in most of the firebug console.
Hope this help.
在您的页面中添加此标签:
事情会成功的。
它在我的系统上运行。
注意:请尝试此解决方案。
Add this Tag in your page :
And the things will work.
Its working on my system.
Note: Do try this solution.
哈维出色答案的图解版本:
A pictorial version of Xavi's excellent answer:
我知道这是一个非常老的问题,但我刚才正在寻找答案。如果不是绝对要求使用 IE 控制台(这不是很好,IMO),那么您可以考虑使用 Firebug Lite (http://getfirebug.com/firebuglite)。这不是一个完美的解决方案,您可能不想将该脚本推送到您的生产环境中,并且它的功能不如 Firebug 那样齐全,但是当您必须使用像这样的低端浏览器时,它在紧要关头非常好IE。
I know this is a REALLY old question, but I was looking for an answer to this just now. If it's not an absolute requirement to use the IE console (which isn't very good, IMO), then you might consider using Firebug Lite (http://getfirebug.com/firebuglite). It's not a perfect solution, and you may not want to push that script out to your production environment, and it's not as full featured as Firebug, but it's pretty good in a pinch when you have to much around with a low-end browser like IE.
有点笨重,但它适用于 DOM 对象:
A bit chunky but it works for DOM objects:
将其转储到现有的 HMTL-Element
我注意到 IE 11 在 1027 个字符后剥离控制台行:-/
当我有一个大对象要转储(12,000 个字符)时,我将其转储到现有的 DIV-oder TextArea-Element 中,从那里我可以复制内容。
Dump it into an existing HMTL-Element
I noticed IE 11 is stripping off console lines after 1027 chars :-/
When I had a large object to dump (12,000 chars) I dumped it into an existing DIV- oder TextArea-Element, from where I could copy the content.
console.log(element.toString()) 可能是你的朋友......
console.log(element.toString()) might be your friend here...