Event.timeStamp
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since иÑÐ»Ñ 2015 г..
ÐозвÑаÑÐ°ÐµÑ Ð²ÑÐµÐ¼Ñ (в миллиÑекÑÐ½Ð´Ð°Ñ ), в коÑоÑом бÑло Ñоздано ÑобÑÑие.
ÐÑимеÑание: ÐÑо ÑвойÑÑво ÑабоÑÐ°ÐµÑ ÑолÑко в Ñом ÑлÑÑае, еÑли ÑиÑÑема ÑобÑÑий поддеÑÐ¶Ð¸Ð²Ð°ÐµÑ ÐµÐ³Ð¾ Ð´Ð»Ñ ÐºÐ¾Ð½ÐºÑеÑного ÑобÑÑиÑ.
СинÑакÑиÑ
event.timeStamp
ÐнаÑение
ÐнаÑение - ÑÑо миллиÑекÑндÑ, пÑоÑедÑие Ñ Ð½Ð°Ñала жизненного Ñикла ÑекÑÑего докÑменÑа до ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ ÑобÑÑиÑ.
In newer implementations, the value is a DOMHighResTimeStamp accurate to 5 microseconds (0.005 ms). In older implementations, the value is a DOMTimeStamp, accurate to a millisecond.
Example
>HTML content
<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>
JavaScript content
function getTime(event) {
var time = document.getElementById("time");
time.firstChild.nodeValue = event.timeStamp;
}
document.body.addEventListener("keypress", getTime);
Result
Reduced time precision
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 |
|---|
| DOM > # ref-for-dom-event-timestampâ > |