XML technologies / SVG / Interactive graphics / Scripting basics

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

SVG offers two kinds of scripting. Scripts can be stored inside the SVG file for interpretation by the browser or viewer. Alternatively, manipulate the SVG graphic with external scripts or programs, for example through VBScript or JavaScript in its containing HTML page. Any object-oriented language can also access an SVG graphic’s Document Object Model (DOM) to make changes, for example VBA or Visual Basic. Server-side scripts such as PHP, Perl and ASP can also access SVG files or convert XML files into SVG.

This chapter covers scripting inside SVG files. A separate, shorter chapter covers manipulating SVG files with external scripts and programming languages. Both use the same DOM; only access and system requirements differ. Internal scripting’s main advantage is that execution depends only on the plug-in or browser’s capabilities. If a plug-in displays the graphic, it executes scripts independently of the browser and its security settings, even when JavaScript is disabled in the browser.

Note:
Whether this remains true with native SVG browser support remains to be seen. Disabling JavaScript might then disable JavaScript inside SVG files too.

SVG Viewer nevertheless uses the browser’s JavaScript implementation. A browser without JavaScript cannot execute scripts even with SVG Viewer. Browsers preventing communication with that implementation cannot run them either; currently these include Netscape 6, Mozilla 0.8.1 and Internet Explorer for Mac OS.

JavaScript syntax inside SVG is independent of the browser and its DOM, though this too could change with the first browsers supporting SVG directly.

Scripts should also run in all browsers using the appropriate plug-in. This differs fundamentally from external scripting, which depends on the browser and currently works only in IE 4.0 or later on Windows, because Internet Explorer for Mac OS and Netscape Navigator prevent access to ActiveX objects or plug-ins.

   

   

 

 

 

back to top