I'm using an SVG as background-image
, via css:
#element {
background-image: url('triangle.svg');
}
Then inside the SVG file I call a function in onload
because I need to pass RGB color parameters to SVG and change the fill of polygon
depending on what the client chooses: / p>
<?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 this onload="setParams"
in SVG (which is like backgounr-image
) is not interpreted when I render the page that is with CSS. That is, my "index" links to CSS but it in turn will not go until SVG interprets the JS.
If I access SVG directly in the url, yes it interprets the JS and executes the function, but through the index that calls the css it does not reach the javascript in svg.