jquery - Embedded iframe within SVG element -
the problem having trying embed iframe within svg element using jquery, , unable iframe drawn. here example stack overflow similar want, except display html snippet:
possible embed youtube video in svg?
my jquery code this,
function showtexttoolbar(selectedgroup){ console.log("here"); var x = +$($(selectedgroup).children().get(0)).attr("x"); var y = +$($(selectedgroup).children().get(0)).attr("y") - 30; console.log(x); console.log(y); var newfosvg = svgeditor.canvas.addsvgelementfromjson({ "element": "foreignobject", "id": "texttool", "attr":{ "x":x, "y":y, "width":"360", "height":"30" } }); var newiframesvg = svgeditor.canvas.addsvgelementfromjson({ "element": "iframe", "attr":{ "width":"360", "height":"30", "src":"http://www.google.com", "xmlns":"http://www.w3.org/1999/xhtml" } }); newfosvg.appendchild(newiframesvg); canv.getelem("svgcontent").appendchild(newfosvg); }
basically, code uses several of pre-built functions (addsvgelementfromjson), add elements svg root present on canvas. i'm using dummy link see if frame show up. @ runtime when call function, no errors present, , svg section updated correctly, nothing displayed.
here svg updated iframe , couple of other objects:
<svg width="600" height="800" xmlns="http://www.w3.org/2000/svg"> <g> <title>layer 1</title> <g id="0ea5f198be28b719853b18c7390003e7"> <rect id="svg_1" width="350" height="50" fill="#ffffff" stroke="#22c" stroke-width="0.5" x="20" y="40"/> </g> </g> <foreignobject height="30" width="360" y="10" x="20"> <iframe xmlns="http://www.w3.org/1999/xhtml" src="http://www.google.com" height="30" width="360"/> </foreignobject> </svg>
i seem have gotten iframe embed properly, nothing displayed on svg canvas. appreciated.
update: moving foreignobject element inside of initial group, can drawn, empty. iframe still not being displayed. also, creating dummy page embedded iframe, able see iframe contents:
<!doctype html public "-//w3c//dtd html 5.0 frameset//en"> <html> <body> <iframe src="test.svg" width="600" height="600"></iframe> </body> </html>
and test.svg contains:
<svg width="600" height="800" xmlns="http://www.w3.org/2000/svg"> <g> <title>layer 1</title> <g id="0ea5f198be28b719853b18c739002923" name="text_free"> <rect y="40" x="20" stroke-width="0.5" stroke="#22c" fill="#ffffff" height="50" width="350" name="border"/> <text y="60" x="40" xml:space="preserve" text-anchor="left" font-family="serif" font-size="12" name="data" opacity="100" stroke-width="0" stroke="#000000" fill="#000000"></text> </g> <g id="0ea5f198be28b719853b18c7390003e7" name="text_free"> <rect y="90" x="20" stroke-width="0.5" stroke="#22c" fill="#ffffff" height="50" width="350" name="border"/> <text y="110" x="40" xml:space="preserve" text-anchor="left" font-family="serif" font-size="12" name="data" opacity="100" stroke-width="0" stroke="#000000" fill="#000000"></text> </g> <foreignobject height="500" width="500" y="200" x="70"> <iframe xmlns="http://www.w3.org/1999/xhtml" src="http://www.google.com" height="500" width="500"/> </foreignobject> </g> </svg>
i ended floating div around page toolbar wanted. didn't need draw on svg toolbar. works better floating div.
update - looking achieve original goal, 1 must use jquery append svg namespaced foreign object node base svg.
Comments
Post a Comment