As i can guess from others replies, you have to synchronize yourself html and svg. 1) add a global var in your html, 2) set that global var when you load your svg, in the init() function or, if your svg document is too long or your server too slow, add a script section at the end of your svg, 3) in your html, function sayHello, test if the global var is set. if not, wait few milliseconds and loop until the svg is loaded.
Philippe http://www.visualkit.com competition 3dviastudio vs webgl : 1000 euros to win http://labo.visualkit.com/competitions/node/142 --- In [email protected], "gmcaulee" <gmcauley@...> wrote: > > > I would like to call a script function in a SVG document that is embedded in > an HTML document. The following HTML and SVG files work in Firefox, Opera, > IE9 but not Chrome (have not tested in Safari). > > My questions are: > > 1) How can I get this to work in Chrome? > 2) Is there a general way to do this that will work for all browsers? > 3) If the answer to 2) is no, what are my options? > > TIA > > *** The HTML: *** > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd"> > <html> > <head> > <title>Test</title> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> > > <script type="text/javascript"> > <!-- > > var svgdoc = null; > var svgwin = null; > > function init() { > > var embed = document.getElementById('embed'); > svgdoc = embed.getSVGDocument(); > if (svgdoc && svgdoc.defaultView) > svgwin = svgdoc.defaultView; > sayHello(); > > } > > function sayHello() { > svgwin.sayHello(); > } > > //--> > </script> > </head> > <body onload="init()"> > <embed id="embed" src="test.svg" width="300" height="200" > type="image/svg+xml" /> > </body> > </html> > > *** The SVG: *** > > <?xml version="1.0"?> > <svg xmlns="http://www.w3.org/2000/svg" > xmlns:xlink="http://www.w3.org/1999/xlink" width="200px" height="200"> > <script type="text/javascript"><![CDATA[ > > function sayHello() { > alert("Hello from test.svg!!!"); > } > > // ]]></script> > <defs> > <rect id="bg_rect" x="0" y="0" width="200" height="200" > fill="#ccffff"/> > <path id="path1" d="M -10 5 L 40 5 L 40 50 L -10 50 L -10 5" > style="fill:#000000;"/> > </defs> > <use x="0" y="0" xlink:href="#bg_rect"/> > <g> > <rect id="rect1" x="140" y="48" width="231" height="213" > transform="matrix(0.352113,0,0,0.352113,-34.1549,0)" fill="rgb(0,143,0)"/> > <polygon id="shape1" points="457,124 526,96 457,68 420,17 > 383,68 314,96 383,124 420,175 457,124" fill="rgb(158,0,76)" > transform="matrix(0.352113,0,0,0.352113,-10.564,15.1411)"/> > <polygon points="524,253 598,295 590,389 503,463 424,337 > 428,233" transform="matrix(0.352113,0,0,0.352113,-34.1549,0)" > fill="rgb(228,14,242)"/> > <polygon id="shape3" points="392,380 346,450 243,467 160,419 > 160,341 243,293 346,310" transform="matrix(0.352113,0,0,0.352113,-34.1549,0)" > fill="rgb(251,0,55)"/> > </g> > <animate attributeName="fill-opacity" attributeType="CSS" from="1.0" > to="0.0" begin="0" dur="5s" fill="freeze" repeatCount="indefinite" > xlink:href="#shape1"/> > <animateMotion repeatCount="indefinite" dur="5s" rotate="0" > fill="freeze" xlink:href="#shape3"> > <mpath xlink:href="#path1"/> > </animateMotion> > </svg> > ------------------------------------ ----- 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: [email protected] [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/

