Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not entirely sure what sort of answer you're looking for, so I apologize if this isn't anything close. ;)</p> <hr> <p>By <strong><em>custom</em></strong>, do you mean <strong><em>custom actions</em></strong>, <strong><em>custom triggers</em></strong>, or truly <strong><em>custom events</em></strong>?</p> <p>E.g.: A <strong><em>custom action</em></strong> would respond to a pre-defined event (say, a mouse click), a <strong><em>custom trigger</em></strong> would be faking a mouse click via script, and a <strong><em>custom event</em></strong> would be a listener that's not defined by the language or isn't readily available.</p> <p>If you're looking for <strong>custom events</strong>, I can't really help you. Though, I don't think there's much support for them in JavaScript.</p> <hr> <p>To define an <strong>Action</strong>...</p> <p>Events are normally established via pre-defined properties of an object, say <code>window.onload</code>. By default, they are all equal to <code>undefined</code> or <code>null</code>. So, to put them to use, you have to set them to the value of a function.</p> <p>You can use an "anonymous" function:</p> <pre><code>window.onload = function (eventObject) { /* ... */ }; </code></pre> <p>Or set them to a function reference (not the same, but similar to a pointer):</p> <pre><code>function handleOnload(eventObject) { /* ... */ } window.onload = handleOnload; /* note the lack of parenthesis */ </code></pre> <p>When the event is triggered, the function is called. So, in either setup, when the page finishes loading, the code you place instead of <code>/* ... */</code> will be executed.</p> <p>There's also more formal methods available for creating events. W3C defines <code>addEventListener</code> while IE uses <code>attachEvent</code>. <a href="http://www.quirksmode.org/js/events_advanced.html" rel="nofollow noreferrer">More info</a>.</p> <p>There are plenty of references available for learning the list of available events. Here's 2 that should give you a good base:</p> <ul> <li><a href="http://www.w3schools.com/jsref/jsref_events.asp" rel="nofollow noreferrer">W3Schools</a></li> <li><a href="https://developer.mozilla.org/en/DOM/element#Event_Handlers" rel="nofollow noreferrer">MDC</a></li> </ul> <hr> <p>The browser usually handles the triggering of events -- either for browser events (<code>onload</code>) or user events (<code>onclick</code>). The property and function are meant to respond.</p> <p><strong>Triggering</strong> your own event isn't the easiest thing to accomplish. To completely define an <code>Event</code> object takes some work -- and <a href="http://www.javascriptkit.com/jsref/event.shtml" rel="nofollow noreferrer">varies between browsers</a>.</p> <p>Though, if you don't need the <code>Event</code> object, you can simply call the event:</p> <pre><code>window.onload(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload