I have an SVG document and I want to include a script in it (using the <script>
). Inside this script, I want to configure a function that will be called when the document is loaded and available for manipulation.
If I were to do this using HTML and jQuery, I would just use $(document).ready(...)
. I want to do the same in an SVG document, but obviously I cannot use jQuery in the same way.
In general, what I'm looking for is something like:
test.svg:
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <script type="text/ecmascript" xlink:href="myscript.js" /> </svg>
myscript.js:
function init(evt) { var svgDocument = evt.target.ownerDocument; var svgRoot = svgDocument.documentElement;
I want to try to do this in a script, and not depending on the explicit onload="init()"
in the SVG definition. (I want to write a script that could potentially be included in multiple SVGs without having to have any knowledge of how the script works.)
source share