I have fairly large script within an .svg file and I'd like to get it out of the CDATA section into an external file. How to achieve this?
The HTML regular does not work:
<script type="text/javascript" src="Track_animation.js" />
The documentation I have been able to find only concerns with JS embedded within the SVG itself. Is use of external scripts even possible?
Using OS X and Safari 4.0.4 for rendering.
JavaScript can be added anywhere in an SVG document between the opening and closing <svg> tags. In general, a script should be placed at the end of the document to avoid blocking and allow the script complete access to the DOM.
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
An external JavaScript file must be saved by . js extension.
Try this
<script xlink:href="file_name" />
Maybe you will need to have xmlns:xlink="http://www.w3.org/1999/xlink"
as attribute in your <svg ... >
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With