On Wed, 28 Nov 2007 04:11:41 +0100, ddailey <[EMAIL PROTECTED]> wrote:
> Hi Nico, > > What a fun problem! > > I fiddled around with it just enough to confirm what seems like odd > behavior in the browsers: > > The enclosed code (with a simple .js file of some sort added on ) shows > very different behavior in Opera 9.5alpha, FF1.5 and IE > with FF able to run the code from the <script> built through DOM. FF > behaves the way I would expect it to. Ok, that is contrary to my experiments :) See below for source of that. > I am not sure where within DOM one would expect the text of a .js (or > .es) file to actually appear, which is why I was experimenting with > various DOM explorations here. If the commented out code (both SVG and > JavaScript) is commented back in then all three browsers see three > script tags, but only in the first case, when the code is provided > in-line, can I figure out how to interrogate the source code > programmatically. Only in FF is the script, thusly constructed, > executable. This is another problem, no? You're looking for a way of getting the text content of a script element that has external content? > Since FF works the way I expect it should, it is probably the one which > is buggy. Erik Dahlstrom has pointed out that some of the CDATA hoopla > that I typically use is more extravagant than it needs to be, so in this > context my extraneous hoopla could prove problematic since it does pop > up as the nodeValue of the script that is commented out. Erik and maybe > Martin H. have also mentioned the use of href.baseVal in setting xlinks, > but this is on my list of things to ask about sometime, so am not sure > why or when one would do that. > > cheers, > David > ------------------------- > <svg xmlns="http://www.w3.org/2000/svg" width="100%" > xmlns:xlink="http://www.w3.org/1999/xlink" onload="start()" > viewBox="0 0 100 100"> > <script><![CDATA[ > svgRoot=document.documentElement > svgNS="http://www.w3.org/2000/svg" > xlinkNS="http://www.w3.org/1999/xlink" > svgRoot.setAttribute("onclick","runit()") > function start(){ > var s = document.createElementNS(svgNS,"script"); > svgRoot.appendChild(s); > s.setAttributeNS(xlinkNS,"xlink:href","xxxx.js"); > SCR=document.getElementsByTagName("script") > > alert(SCR.length+SCR.item(0).nodeName+SCR.item(0).nodeName+SCR.item(0).firstChild.nodeValue) > alert(SCR.length+SCR.item(1).nodeName) > alert(SCR.item(1).getAttribute("xlink:href")) Replacing the line above with: alert(SCR.item(1).getAttributeNS(xlinkNS, "xlink:href")) gives me the correct xlink:href back in Opera as well. The question is whether this is correct in Firefox or not, is the name given to getAttribute a localName or a qualifiedName? The DOM specs are not very clear about that subject. And the same thing goes for setAttribute. Now logged as bug 300509 in Opera's bugtracker. > //alert(SCR.item(2).nodeName) > //alert(SCR.item(2).getAttribute("xlink:href")) > runit() > } > //]]></script> > <!--<script xlink:href="xxxx.js"></script>--> > > <rect x="0" y="0" id="R" height="100" width="100" fill="red" /> > > </svg> So, here is the simple variant that I made up which works fine in the browsers I tested: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 768" onload="init()"> <script> var svgNS="http://www.w3.org/2000/svg"; var xlinkNS="http://www.w3.org/1999/xlink"; function init() { var s = document.createElementNS(svgNS,"script"); s.setAttributeNS(xlinkNS,"xlink:href","myscript.es"); document.documentElement.appendChild(s); } </script> </svg> The file myscript.es: alert("hello"); Cheers /Erik -- http://my.opera.com/MacDev_ed/blog ----- To unsubscribe send a message to: [EMAIL PROTECTED] -or- visit http://groups.yahoo.com/group/svg-developers and click "edit my membership" ---- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/svg-developers/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/svg-developers/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

