aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/event/timestamp/index.html
blob: b4e2e7472d216b0a11d0d0a11c8969acffec653a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
title: Event.timeStamp
slug: Web/API/Event/timeStamp
translation_of: Web/API/Event/timeStamp
---
<div>{{APIRef("DOM")}}</div>

<p><span id="result_box" lang="ru"><span>Возвращает время (в миллисекундах), в котором было создано событие.</span></span></p>

<div class="note">
<p><strong>Примечание: </strong><span id="result_box" lang="ru"><span>Это свойство работает только в том случае, если система событий поддерживает его для конкретного события.</span></span></p>
</div>

<h2 id="Синтаксис"><span class="short_text" id="result_box" lang="ru"><span>Синтаксис</span></span></h2>

<pre class="syntaxbox"><var>event</var>.timeStamp
</pre>

<h3 id="Значение">Значение</h3>

<p>Значение - это миллисекунды, прошедшие с начала жизненного цикла текущего документа до создания события.</p>

<p>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>

<h2 id="Example">Example</h2>

<h3 id="HTML_content">HTML content</h3>

<pre class="brush: html">&lt;p&gt;
  Focus this iframe and press any key to get the
  current timestamp for the keypress event.
&lt;/p&gt;
&lt;p&gt;timeStamp: &lt;span id="time"&gt;-&lt;/span&gt;&lt;/p&gt;</pre>

<h3 id="JavaScript_content">JavaScript content</h3>

<pre class="brush: js">function getTime(event) {
  var time = document.getElementById("time");
  time.firstChild.nodeValue = event.timeStamp;
}
document.body.addEventListener("keypress", getTime);</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample("Example", "100%", 100)}}</p>

<h2 id="Reduced_time_precision">Reduced time precision</h2>

<p>To offer protection against timing attacks and fingerprinting, the precision of <code>event.timeStamp</code> might get rounded depending on browser settings.<br>
 In Firefox, the <code>privacy.reduceTimerPrecision</code>  preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms.</p>

<pre class="brush: js">// reduced time precision (2ms) in Firefox 60
event.timeStamp;
// 1519211809934
// 1519211810362
// 1519211811670
// ...


// reduced time precision with `privacy.resistFingerprinting` enabled
event.timeStamp;
// 1519129853500
// 1519129858900
// 1519129864400
// ...
</pre>

<p>In Firefox, you can also enabled <code>privacy.resistFingerprinting</code>, the precision will be 100ms or the value of <code>privacy.resistFingerprinting.reduceTimerPrecision.microseconds</code>, whichever is larger.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("DOM WHATWG", "#dom-event-timestamp", "Event.timeStamp")}}</td>
   <td>{{Spec2("DOM WHATWG")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("DOM4", "#dom-event-timestamp", "Event.timeStamp")}}</td>
   <td>{{Spec2("DOM4")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 Events", "#Events-Event-timeStamp", "Event.timeStamp")}}</td>
   <td>{{Spec2("DOM2 Events")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat}}</p>