This is an example where we call a Javascript function that is located in an SVG file from within Javascript within an HTML file. When the reader clicks on the "Hit me" button the Javascript code in the HTML document first calls alert() showing the SVG document object. It then calls alert to show the result of calling the invokeSVG() function in that SVG document. We are passing an value from HTML to the SVG-housed function and getting a value back.

The invokeSVG() function in the SVG document also calls alert, announcing it is being called and showing its input value.

In order to make this work, we must explicitly add the SVG function as an element of the SVG document

document.invokeSVG = invokeSVG;



Duncan Temple Lang <duncan@wald.ucdavis.edu>
Last modified: Thu Aug 20 18:38:20 PDT 2009