Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG in HTML with a script element

Tags:

html

svg

I have an inline SVG code inside a HTML page,

<body>
<div style="width:1000px;height:1000px">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="svgcanvas" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="viewport">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
<script xlink:href="js/SVGPan.js" type="text/javascript"/>
</svg>

The script is invoked correctly in Firefox 7.0, but not in Chrome 16.0. Why is this so? And what modifications should I make in the code to invoke the javascript in Chrome too?

like image 356
arv100kri Avatar asked Jan 01 '12 12:01

arv100kri


1 Answers

Interesting question.

Some things to note.

Inside normal HTML, <script ... /> would not be self closing and anything that followed would be part of the contents of the script element.

Inside the <svg> element, <script ... /> is self closing and forms an entire element.

Both Firefox and Chrome get this right.

However, the HTML5 spec says that the script should only be processed when the parser encounters the end tag. Since the element doesn't have an end tag, then, the script should not be processed. This is what Chrome does.

The SVG spec however, requires the script to be run once the element has been closed by any means, not just on an end tag. This is what Firefox does.

IMHO, the HTML5 spec is wrong, and should specify behaviour consistent with SVG.

UPDATE: 10 Aug 2012.

The HTML5 spec (currently WHATWG version only) has been changed so that the SVG script should be run. See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17995

UPDATE: 16 Sep 2012.

The W3C version of the HTML5 spec has now also been corrected.

like image 161
Alohci Avatar answered Oct 08 '22 14:10

Alohci