Hi guys,
I got a document like this:
External javascript code from svg
Re: External javascript code from svg
OK first of all, as you have found the embedded SVG file and the page around it do not share the same DOM, so direct access is not possible.
SVG files support the <script> tag, and this allows you to reference external .js files. Unlike HTML, it does not support a src attribute but uses XML's xlink instead:
eg:
Note you have to define the xlink namespace in the <svg> tag like so:
Some more details at carto.net
Tom
SVG files support the <script> tag, and this allows you to reference external .js files. Unlike HTML, it does not support a src attribute but uses XML's xlink instead:
eg:
Code: Select all
<script type="text/ecmascript" xlink:href="lib.js"></script>
Note you have to define the xlink namespace in the <svg> tag like so:
Code: Select all
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
Some more details at carto.net
Tom