Firefox: <script>'ing driving me up the wall !!!

K

klestes

Hi all -

My apologies for what is probably a newbie post. I'm trying to grok
using javascript with SVG, and have come to learn that anything
involving a <script> tag may or may not work.

My current code looks like:

<?xml version="1.0" ?>
<html xlmns="http://www.w3.org/1999/xhtml">

<title>A title here would be nice</title>


<body>
<h1>Do you see me?</h1>


<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">

<script type="text/javascript" src="test.js" />

<defs>

<g id="friendly" style="fill: none; stroke: black;" >
<rect x="0" y="0" width="30" height="30"
onmouseover="turn_blue(evt)"
/>
</g>

<g id="enemy" style="stroke: red; fill: none" >
<circle cx="10" cy="10" r="10"
onmouseover="turn_red(evt)"
/>
</g>

</defs>


<circle cx="50" cy="50" r="15"
style = "stroke: blue; stroke-width: 3; fill: none"
onmouseover="turn_black(evt)"
/>

<use xlink:href="#friendly" x="0" y="0"
/>

<use xlink:href="#enemy" x="100" y="100" />

</svg>


</body>
</html>

the file test.js:

/*
* File: test.js
*
*/
var old_style = "fill: none; stroke: black; stroke-width: 3";


function turn_red(evt)
{
var c = evt.target;
c.setAttribute("style", "fill: red");
}

function turn_blue(evt)
{
var c = evt.target;
c.setAttribute("style", "stroke: blue; fill: blue");
}


function some_f_here()
{
var a = 1;
}

function turn_black(evt)
{
var obj = evt.target;
obj.setAttribute("style", "fill: black");
}


// end of file.


Maybe I'm just blowing some part of the magic incantations required...I
have observed that, when the <script> block is within the <svg> block
it works, otherwise de nada. I am using the latest, greatest Firefox,
1.5.0.6.

thanks !
K. L.
 
M

Martin Honnen

<?xml version="1.0" ?>
<html xlmns="http://www.w3.org/1999/xhtml">
^^^^^

That needs to be xmlns and not xlmns.


Maybe I'm just blowing some part of the magic incantations required...I
have observed that, when the <script> block is within the <svg> block
it works, otherwise de nada. I am using the latest, greatest Firefox,
1.5.0.6.

Well Firefox 1.5 within XML supports the XHTML script element in the
namespace http://www.w3.org/1999/xhtml and the SVG script element in the
namespace http://www.w3.org/2000/svg. As your root element does not have
the proper xmlns declaration to be an XHTML element any child or
descendant element is not an XHTML element either. And a script element
in no namespace does not have any meaning to load script files or
process script contents. Your SVG svg element has a proper xmlns
declaration and thus its child and descendant elements are recognized as
SVG elements.
 
K

klestes

Thanks Martin ! It makes sense now why <script> within the SVG worked,
and wouldn't work anywhere else - dyslexia this damn !

Now to return to sanity :)
-KL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top