Answer the question
In order to leave comments, you need to log in
How to handle right click on svg?
I have a svg rectangle:
<svg version="1.1"
viewBox="0 0 200 100"
preserveAspectRatio="xMidYMid meet"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns="http://www.w3.org/2000/svg">
<rect id="rect1" class="rct" x="10" y="10" width="80" height="80" rx="20" ry="20" fill="red" />
</svg>
<object id="svg" type="image/svg+xml" data="rectangle.svg" width = "200" height = "200"></object>
Answer the question
In order to leave comments, you need to log in
Try like this
document.getElementById('svg').onload = function() {
var svgDoc = this.contentDocument,
rect = svgDoc.getElementById('rect1');
rect.addEventListener('contextmenu', function(e) {
e.preventDefault();
alert('На меня тычат правой кнопкой мыши!');
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question