The contentScriptType attribute on the 'svg' element specifies the default scripting language for all scripts in the given document.
In the absense of a contentScriptType attribute, the default can be set by a "Content-Script-Type" HTTP header:
Content-Script-Type: <contentType>
User agents shall determine the default scripting language for an SVG document fragment according to the following steps (highest to lowest priority):
Documents that do not specify a default scripting language shall set the default scripting lanuage to "text/ecmascript".
It is also possible to specify the scripting language for each individual 'script' element by specifying a language attribute on the 'script' element.
A 'script' element can appear as a subelement to any 'defs' element. A 'script' element is equivalent to the 'script' element in HTML and thus is the place for scripts (e.g., ECMAScript). Any functions defined within any 'script' element have a "global" scope across the entire current document.
The following is an example of defining an ECMAScript function and defining an event handler that invokes that function:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG December 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19991203.dtd"> <svg width="4in" height="3in"> <defs> <script><![CDATA[ /* Beep on mouseclick */ MouseClickHandler() { beep(); } ]]> </script> </defs> <circle onclick="MouseClickHandler()" r="85"/> </svg>
<!ELEMENT script (#PCDATA)* > <!ATTLIST script language CDATA #IMPLIED %xlinkRefAttrs; xlink:href CDATA #IMPLIED > |
Attribute definitions:
Events can cause scripts to execute when either of the following has occurred:
Related sections of the spec:
The following event attributes are available on many SVG elements, including its graphics elements and its container elements.
Animatable: no.
Animatable: no.
Animatable: no.
A load event is dispatched only to the element to which the event applies; it is not dispatched to its ancestors. For example, if an 'image' element and its parent 'g' element both have event listeners for load events, when the 'image' element has been loaded, only its event listener will be invoked. (The 'g' element's event listener will indeed get invoked, but the invocation will happen when the 'g' itself has been loaded.)
Additionally, SVG's scripting engine needs to have the altKey, ctrlKey and shiftKey properties available.
The SVGScriptElement interface corresponds to the 'script' element.
interface SVGScriptElement : SVGElement { attribute DOMString language; attribute DOMString role; attribute DOMString title; attribute DOMString show; attribute DOMString actuate; attribute DOMString href; attribute DOMString target; }; |
The zoom event handler occurs before the zoom event is processed. The remainder of the DOM represents the previous state of the document. The document will be updated upon normal return from the event handler.
interface SVGZoomEvent : UIEvent { // Information about the specified zoom rectangle in screen units. attribute SVGRect zoomRectScreen; // Information about the previous zoom and pan factors attribute float previousScale; attribute SVGPoint previousTranslate; // Information about the new zoom and pan factors which will // be applied upon normal return from the event handler. attribute float newScale; attribute SVGPoint newTranslate; }; |
The UI event type for a zoom event is: