IE / Edge点击SVG会导致错误 - TypeError:对象不支持属性或方法'模糊'

时间:2016-07-28 23:01:09

标签: javascript angularjs internet-explorer svg microsoft-edge

我使用角度组件(Angular UI分页,虽然我不认为它是导致问题的原因),我的模板包含以下内容......

<my-button ng-click="selectPage(totalPages, $event)">
    <svg>
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="domain.com/scgSprite.svg#arrow"></use>
    </svg>
</my-button>

问题是在MS Edge和IE(但不是chrome)中,单击按钮时出现以下错误。

TypeError:对象不支持属性或方法&#39;模糊&#39;

当我点击按钮但没有图标的边缘时,它不会发生。我必须实际单击按钮上的SVG元素才能得到错误。

真的很感激任何帮助。

修改

我发现angular-ui库中导致错误的行是这些......

if (evt && evt.target) {
    evt.target.blur();
}

我不想编辑图书馆,因为我以后无法将其更新到新版本。

我是否有可能将.blur()函数添加到MS浏览器中的svg元素?

1 个答案:

答案 0 :(得分:2)

这解决了问题

if (typeof SVGElement.prototype.blur == 'undefined') {
    SVGElement.prototype.blur = function(){};
}