--- title: Event.timeStamp slug: Web/API/Event/timeStamp translation_of: Web/API/Event/timeStamp ---
Возвращает время (в миллисекундах), в котором было создано событие.
Примечание: Это свойство работает только в том случае, если система событий поддерживает его для конкретного события.
event.timeStamp
Значение - это миллисекунды, прошедшие с начала жизненного цикла текущего документа до создания события.
In newer implementations, the value is a {{domxref("DOMHighResTimeStamp")}} accurate to 5 microseconds (0.005 ms). In older implementations, the value is a {{domxref("DOMTimeStamp")}}, accurate to a millisecond.
<p> Focus this iframe and press any key to get the current timestamp for the keypress event. </p> <p>timeStamp: <span id="time">-</span></p>
function getTime(event) { var time = document.getElementById("time"); time.firstChild.nodeValue = event.timeStamp; } document.body.addEventListener("keypress", getTime);
{{EmbedLiveSample("Example", "100%", 100)}}
To offer protection against timing attacks and fingerprinting, the precision of event.timeStamp
might get rounded depending on browser settings.
In Firefox, the privacy.reduceTimerPrecision
preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms.
// reduced time precision (2ms) in Firefox 60 event.timeStamp; // 1519211809934 // 1519211810362 // 1519211811670 // ... // reduced time precision with `privacy.resistFingerprinting` enabled event.timeStamp; // 1519129853500 // 1519129858900 // 1519129864400 // ...
In Firefox, you can also enabled privacy.resistFingerprinting
, the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds
, whichever is larger.
Specification | Status | Comment |
---|---|---|
{{SpecName("DOM WHATWG", "#dom-event-timestamp", "Event.timeStamp")}} | {{Spec2("DOM WHATWG")}} | |
{{SpecName("DOM4", "#dom-event-timestamp", "Event.timeStamp")}} | {{Spec2("DOM4")}} | |
{{SpecName("DOM2 Events", "#Events-Event-timeStamp", "Event.timeStamp")}} | {{Spec2("DOM2 Events")}} | Initial definition |
{{Compat("api.Event.timeStamp")}}