无法使用SVGweb在Internet Explorer中将侦听器添加到SVG [英] can't add listener to a SVG in Internet Explorer using SVGweb
问题描述
此代码在firefox中运行良好,但在IE中却没有。我已经阅读了SVGWeb的文档( http://svgweb.googlecode.com/svn/trunk/docs/UserManual.html ),但我没有找到/理解解决方案,任何想法?
This code works great in firefox, but not in IE i've read the documentation of SVGWeb (http://svgweb.googlecode.com/svn/trunk/docs/UserManual.html), but i don't find/understand the solution, any idea?
window.onsvgload = function() {
carga();
var mySVG = document.getElementById("mySVGObject").contentDocument;
mySVG.addEventListener('click', function(evt) {
alert(evt.target.id);
}, false);
}
我正在使用这样的东西在IE中没有问题:
Im using things like this in IE without problems:
mySVG.getElementById('Color2').style.fill='#00cc00'
使用该代码我可以更改形状中的颜色和文本。但我不能让听众在IE中工作。
with that code I can change colors and texts in the shape. But i cannot make the listener work in IE.
编辑:这适用于Chrome,FF和IE9,我需要它才能在IE7上运行。
这是我加载svg对象的方式
this works in Chrome, FF and IE9, I need it to work on IE7. This is how I load the svg object
<div style="text-align:center" id="mapaSvg" >
<!--[if !IE]>-->
<object data="ca.svg" type="image/svg+xml"
width="700" height="800" id="mySVGObject" > <!--<![endif]-->
<!--[if lt IE 9]>
<object src="ca.svg" classid="image/svg+xml"
width="700" height="800" id="mySVGObject" > <![endif]-->
<!--[if gte IE 9]>
<object data="ca.svg" type="image/svg+xml"
width="700" height="800" id="mySVGObject" > <![endif]-->
</object>
</div>
<div style="text-align:center">
IE开发工具显示错误:触发onload时出错:不支持在线:
The IE development tools show the error: "Error while firing onload: Not supported" On the line:
mySVG.addEventListener('click', function(evt) {
alert(evt.target.id);
}, false);
在这里你可以看到一个SVGWEB在动态线路鼠标悬停的IE,FF,Chrome上工作的例子:
https://www.destatis.de/bevoelkerungspyramide/
Here you can see an example of SVGWEB working in IE, FF, Chrome on mouse over of dynamic lines: https://www.destatis.de/bevoelkerungspyramide/
谢谢!
推荐答案
尝试调用 addEventListener
在此块内而不是 onsvgload
:
Try to call addEventListener
inside this block instead onsvgload
:
window.addEventListener('SVGLoad', function() {
// all SVG loaded and rendered
}, false)
这些结构是相同的,但我做了这个假设是因为一个错误:触发onload时出错:不支持
These constructions are equal but I make this assumption because of an error: "Error while firing onload: Not supported"
这篇关于无法使用SVGweb在Internet Explorer中将侦听器添加到SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!