I have tried to change the images on my site from img
to svg
, changing img
tags to embed
and object
tags. Bu
I wrapped the 'svg' tag in 'a' tag and put the onClick event in the 'a' tag
Click on SVG's <g>
element in <object>
with click event. Works 100%. Take a look on the nested javascript in <svg>
. Don't forget to insert window.parent.location.href=
if you want to redirect the parent page.
https://www.tutorialspoint.com/svg/svg_interactivity.htm
It worked by simply replacing the <embed/>
tag with <img/>
and deleting the type attribute.
For instance, in my code, instead of:
<embed src=\"./images/info_09c.svg\" type=\"image/svg+xml\" width=\"45\" onClick='afiseaza_indicatie($i, \"$indicatii[$i]\")'>
which does not answer the clicking, I wrote:
<img src=\"./images/info_09c.svg\" height=\"25\" width=\"25\" onClick='afiseaza_indicatie($i, \"$indicatii[$i]\")'>
It works in Internet Explorer and Google Chrome, and I hope that in the other browsers too.
You could use following code:
<style>
.svgwrapper {
position: relative;
}
.svgwrapper {
position: absolute;
z-index: -1;
}
</style>
<div class="svgwrapper" onClick="function();">
<object src="blah" />
</div>
b3ng0 wrote similar code but it does not work. z-index of parent must be auto.
Perhaps what you're looking for is the SVG element's pointer-events property, which you can read about at the SVG w3C working group docs.
You can use CSS to set what happens to the SVG element when it is clicked, etc.
In case you're fine with wrapping the svg in another element (a
for example) and putting onclick
on the wrapper, svg {pointer-events: none;}
CSS will do the trick.