0

I want to access attributes of my svg:

<object id="mainIcon" type="image/svg+xml" data="icons/ribbon.svg"></object>

I read that it should be possible with documentElement or getSVGDocument, but both of them return null. Further searching reveals that they don't work locally only by web server... All answers I seem to find seem to be solely concerned with web servers and offer no local solutions.

Chlodio
  • 205
  • 1
  • 3
  • 10
  • 5
    *"All answers I seem to find seem to be solely concerned with web servers and offer no local solutions."* That's because browsers behave in slightly arcane and varying ways when dealing with "local" resources (resources identified by `file://` URIs). Your best bet is almost always to use a local webserver and serve from `http://localhost` URIs instead. Installing a local web server is quite easy in most environments. – T.J. Crowder Mar 17 '21 at 09:15
  • [This is related](https://stackoverflow.com/questions/9393532/cross-domain-iframe-issue) but I've no idea if you can persuade postMessage to work from a pure SVG document. – Quentin Mar 17 '21 at 09:18
  • 1
    No, browsers security models generally don't permit this. Use a web server if you want to develop web pages. – Robert Longson Mar 17 '21 at 10:15
  • 2
    @Quentin [yes you could](https://jsfiddle.net/o3u95yeb/), though there is an interop' issue here with FF where they don't allow the use of 's WindowProxy on cross-origin docs. (Using an – Kaiido Mar 17 '21 at 10:26

0 Answers0