4
I’m using an SVG as background-image
, via css:
#element {
background-image: url('triangle.svg');
}
Then inside the SVG arch I call a function in the onload
because I need to pass RGB color parameters to SVG and change the Fill of polygon
depending on what the customer has chosen:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.2" baseProfile="tiny" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="114px" height="66px" viewBox="0 0 114 66" xml:space="preserve" onload="setParams()">
<script type="text/javascript">
<![CDATA[
function setParams() {
alert('funcao!');
}
]]>
</script>
<polygon id="polygon" points="114,0 0,66 114,66"/>
</svg>
The problem is that onload="setParams"
in the SVG (which is as backgounr-image
) is not interpreted at the time I replay the page with the CSS. That is, my "index" links CSS but it in turn does not go until SVG interprets JS.
If I access the SVG directly in the url ai yes it interprets the JS and executes the function, but through the index that calls the css does not reach the javascript in svg.
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero