搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Why is Date() constructor is unavailable in Firefox?

  • 5 个回答
  • 1 人有此问题
  • 8 次查看
  • 最后回复者为 cor-el

more options

Am using javascript in simple web app. Works fine in Chrome, but in Firefox the Date() object type does not work. Specifically, console.log(new Date()) prints "<unavailable>" on the browser console.

Am using javascript in simple web app. Works fine in Chrome, but in Firefox the Date() object type does not work. Specifically, console.log(new Date()) prints "<unavailable>" on the browser console.

所有回复 (5)

more options

Your code works in the Web Console* if I open it below this page.

<center></center>

Q: Does your app use any libraries that override or redefine the Date() constructor?


* You can open the Web Console in the lower part of the tab using either:

  • "3-bar" menu button > Web Developer > Web Console
  • (menu bar) Tools > Web Developer > Web Console
  • (Mac) Command+option/alt+k

Ref.

由jscher2000 - Support Volunteer于修改

more options

Does not work for me. Just to simplify things, I created a tiny example that demonstrates the problem. Specifically, I created a file containing

<!doctype html5>
<html>
<script>
console.log(new Date());
</script>
</body>
</html>

and opened it as a file. In chrome, this displays the current date/time on the console. In Firefox, it shows <unavailable> on the console. Does Firefox need something more in the script to make the Date object available?

Thanks,

由cor-el于修改

more options

Clarification to last post. The tool is removing a portion of the example file. I've been futzing around with this trying to get it to show the complete file contents, but have not figured out how to do that. So here is an explanation.

The file starts with a "doctype html5" tag, followed by an "html" tag and a "body" tag. Then comes the "script tag" and the console.log(new Date()). Then, closing versions of all tags, in the reverse order.

Hope that makes things clear.

Jon

more options

To post code here, you can replace < with &lt; so the wiki software doesn't eat your tags.

In this case, the Browser Console and the Web Console behave differently with

console.log(new Date());

The tab-specific Web Console gives you access to Date() as an object you can explore by clicking the gray triangle to the left. See my earlier screenshot. The global Browser Console does not for some reason, instead it shows "unavailable." But the Date() object is indeed instantiated. If you try

console.log(new Date().toString());

the two consoles will both display the results.

Ref.

由jscher2000 - Support Volunteer于修改

more options

I don't know whether a website can access to console if that is what you are doing (i.e. you use this code in a website) because a website is in a sandbox when multi-process is enabled.