javascript - getSVGDocument is returning NULL in Chrome -


this question has answer here:

i'm starting use svg , have following code:

html

<embed id="embed" src="svg.svg" type="image/svg+xml" width="400" height="300" >  <object id="object" data="svg.svg" type="image/svg+xml" width="400" height="300"></object> 

javascript

$(window).load(function (){ //alert("document loaded, including graphics , embedded documents (like svg)");      var svgdoc_embed = document.getelementbyid("embed").getsvgdocument();     alert("my svgdoc_embed => " + svgdoc_embed);      var svgdoc_object = document.getelementbyid("object").getsvgdocument();     alert("my svgdoc_object => " + svgdoc_object);    }); 

in firefox browser works well

my svgdoc_embed => [object svgdocument] svgdoc_object => [object svgdocument] 

but not work on chrome browser.

my svgdoc_embed => null svgdoc_object => null 

i have searched internet can not find works

any suggestion welcome

==========================================================================

i try opening chrome js console , type in:

document.getelementbyid ("object"). getsvgdocument ();

the result null.

also change code to:

$ ("embed"). load (function () { svgdoc_embed var = document.getelementbyid ("embed"). getsvgdocument (); alert ("my # embed svgdoc_embed =>" + svgdoc_embed); });    $ ("object"). load (function () {   svgdoc_object var = document.getelementbyid ("object"). getsvgdocument (); alert ("my # object svgdoc_object =>" + svgdoc_object);   }); 

and not give results.

any suggestion welcome.

i believe getsvgdocument() deprecated , didn't work in copy of ff. try using firstelementchild instead:

var svg = document.getelementbyid("object").firstelementchild; 

or access svg element directly with:

var svg = document.getelementbyid("foo"); 

where "foo" value of id attribute of root svg element.

<svg id="foo"> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -