Home | History | Annotate | Download | only in static
      1 <p>
      2 An <code>Event</code> is an object
      3 that allows you to be notified
      4 when something interesting happens.
      5 Here's an example of using the
      6 <code>chrome.tabs.onCreated</code> event
      7 to be notified whenever there's a new tab:
      8 </p>
      9 
     10 <pre>
     11 chrome.tabs.onCreated.<b>addListener(function(</b>tab<b>) {</b>
     12   appendToLog('tabs.onCreated --'
     13               + ' window: ' + tab.windowId
     14               + ' tab: '    + tab.id
     15               + ' index: '  + tab.index
     16               + ' url: '    + tab.url);
     17 <b>});</b>
     18 </pre>
     19 
     20 <p>
     21 As the example shows,
     22 you register for notification using <code>addListener()</code>.
     23 The argument to <code>addListener()</code>
     24 is always a function that you define to handle the event,
     25 but the parameters to the function depend on
     26 which event you're handling.
     27 Checking the documentation for
     28 <a href="tabs.html#event-onCreated"><code>chrome.tabs.onCreated</code></a>,
     29 you can see that the function has a single parameter:
     30 a <a href="tabs.html#type-Tab">Tab</a> object
     31 that has details about the newly created tab.
     32 </p>
     33 
     34 <h2>
     35 Methods
     36 </h2>
     37 
     38 <p>
     39 You can invoke the following methods on any <code>Event</code> object:
     40 </p>
     41 
     42 <pre>
     43 void addListener(function callback(...))
     44 void removeListener(function callback(...))
     45 bool hasListener(function callback(...))
     46 </pre>
     47 
     48 <!-- [PENDING: explain removeListener and hasListener] -->
     49