¿How to have a transparent background on an `<object>` embedded SVG?
When SVGs are embedded into the page using an
<img> tag, scripts don't run and user interactions don't work.
Using an <object> tag fixes those issues, but causes the element to have a white background, regardless of the color-scheme value.
What I'd really like is to allow SMIL & CSS user interactions, but limit script execution since I'll be displaying images from unknown sources. I know <iframe> has some sandboxing options, but also doesn't allow compositing.
Actually, if I have a color-scheme in the SVG document it'll darken the background. Or, if I inline the SVG, it'll do true transparency.
I'm tempted to write a script to fetch all the SVGs and insert them into the document DOM. That will open the door to scripts, but I guess I could sanitize the images before including them.
¿Is that a fool's errand? ¿How would y'all handle this background color problem?
5 Replies
have you tried to inherit the background color in the <object>?
Yeah. Setting
background on object has no effect.have you tried to add
allowbackground?Inline them with no fill for svg and remove any bgs
You could try something like this but in my tests I couldn't get it to respect the width. I also don't know if this will allow your interactions