Why is Date() constructor is unavailable in Firefox?
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)
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 於
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 於
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
To post code here, you can replace < with < 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 於
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.