javascript - Convert link to a SVG into an inline SVG element -


is possible convert link external svg such http://upload.wikimedia.org/wikipedia/en/4/4a/commons-logo.svg element?

my first approach grab source code of svg page, not possible external sources in javascript.

this cleanest way load svg file inline, create div on web page , load svg file via xmlhttprequest , place response text div using innerhtml

you can inspect/change file needed.

below example calls file web page:

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>load svg file file inline</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body style='padding:0px;font-family:arial'> <center><h4>load svg file inline</h4> <div style='width:90%;background-color:gainsboro;text-align:justify;padding:10px;border-radius:6px;'> load svg file inline svg. provides dynamic svg applications seamless dom access elements. uses <b>xmlhttprequest</b>. can loaded div's <b>innerhtml</b> via string dump (<b>responsetext</b>). </div> <div id="svgdiv"></div> <p><button onclick=changesomevalues()>change</button></p> svg dom:<br /> <textarea id=mysvgvalue style='width:90%;height:200px;font-size:120%;font-family:lucida console;'></textarea>   <br />javascript:<br /> <textarea id=jsvalue style='border-radius:26px;font-size:110%;font-weight:bold;color:midnightblue;padding:16px;background-color:beige;border-width:0px;font-size:100%;font-family:lucida console;width:90%;height:400px'></textarea> </center> <div id='browserdiv' style='padding:3px;position:absolute;top:5px;left:5px;background-color:gainsboro;'></div>  <script id=myscript> function loadsvgasxml() {     var svgfile="http://upload.wikimedia.org/wikipedia/en/4/4a/commons-logo.svg"     var loadxml = new xmlhttprequest;     function handler(){         if(loadxml.readystate == 4 &&loadxml.status == 200){                svgdiv.innerhtml=loadxml.responsetext                mysvgvalue.value= svgdiv.innerhtml         }     }     if (loadxml != null){         loadxml.open("get", svgfile, true);         loadxml.onreadystatechange = handler;         loadxml.send();     } } //--button--- function changesomevalues() {     path4653.style.fill="green"     mysvgvalue.value=svgdiv.innerhtml } </script> <script> document.addeventlistener("onload",init(),false) function init() {     loadsvgasxml()     jsvalue.value=myscript.text     mysvgvalue.value=svgdiv.innerhtml } </script> </body> </html> 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -