搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

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.