mc9
mc9

Reputation: 6349

How does getTimezoneOffset know host system's timezone?

I would like to know how Date.prototype.getTimezoneOffset() is able to get the timezone setting of the host system.

As I know JavaScript in browser is executed in a sandboxed environment for security reasons. How can it retrieve information such as this? One step further, what can and can't JavaScript run in browser access in the host system?

Upvotes: 1

Views: 41

Answers (2)

Evert
Evert

Reputation: 99581

Built-in javascript API's have all kinds of hooks into the host system. Many built-in standard APIs will do something that you can't write yourself.

The sandbox only applies to you, as a person who writes javascript. Not browser vendors who implement the standard library.

Upvotes: 3

NineBerry
NineBerry

Reputation: 28499

The function is not implemented in JavaScript code, but it is provided by the JavaScript runtime that is part of the browser. Functions implemented as part of the runtime can do stuff that your Javascript code cannot do.

Upvotes: 0

Related Questions