Do – Avatar May 13 '22 at 10:17

1

I've done this and it worked for me.

But I think there should be the mysterious //<!\[CDATA\[ stuff:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC
  "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  <svg width="200"
       height="200"
       zoomAndPan="disable"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink"
       xml:space="preserve">
    <!-- Script linked from the outside-->
    <script xlink:href="linked_script.js" />
    <script>
      //<![CDATA[
        alert("ble");
      ]]>
    </script>
  </svg>

This is the file I embed it in (and it alerts as expected):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Svg embeding test</title>
  </head>
  <body>
    <embed src="test.svg" type="image/svg+xml" /> 
  </body>
</html>
Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
0

Following Robert Longson answer: In my case I had to <embed> the .svg because my CMS (joomla) didn't allow me to put a src attribute into the object tag and also worked.

Also you have to be sure that MIME type image/svg+xml is allowed on your server.

vicgilbcn
  • 149
  • 3