SVG中外来物体的特征检测
我在SVG中使用foreignObject元素,但是IE9不支持该元素。我正在寻找一种检测此功能的方法。Modernizr没有检测到此功能,而且我似乎无法像使用矩形(createSVGRect)那样使用createSVGForeignObject(在SVGSVGElement上不可用)SVG中外来物体的特征检测,svg,feature-detection,Svg,Feature Detection,我在SVG中使用foreignObject元素,但是IE9不支持该元素。我正在寻找一种检测此功能的方法。Modernizr没有检测到此功能,而且我似乎无法像使用矩形(createSVGRect)那样使用createSVGForeignObject(在SVGSVGElement上不可用) 谢谢 如果您想使用foreignObject,这应该是可行的,因为它集成了html内容 <switch> <g requiredFeatures="http://www.w3.org/TR/
谢谢 如果您想使用foreignObject,这应该是可行的,因为它集成了html内容
<switch>
<g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" requiredExtensions="http://www.w3.org/1999/xhtml">
<foreignObject >
</foreignObject>
</g>
<text font-size="10" font-family="Verdana">
No foreignObject
</text>
</switch>
有一种方法可以在JS中测试此功能,下面是从最近提交Modernizer()中借用的:
需要明确的是:
createSVGRect()
不创建rect元素,而是创建一个rect对象。要创建元素,只需使用document.createElements(…)
http://www.w3.org/TR/SVG11/feature#Extensibility
是SVG 1.1中为foreignObject元素定义的featurestring,如果您想测试它的话。您可以在requiredExtensions(空格分隔)中列出多个值。感谢您的帮助。这种技术在用户代理支持不可用的情况下提供了另一种呈现方式。然而,我正在寻找Javascript解决方案(针对条件代码)。这就是我将要使用的/SVGForeignObject/.test(document.createElements('http://www.w3.org/2000/svg.appendChild(document.createElements('http://www.w3.org/2000/svg“,”foreignObject'))。toString())
简单地SVGForeignObjectElement的类型!='未定义的“
也可以做这项工作。document.implementation.hasFeature(“w3.org/TR/SVG11/feature#Extensibility”,“1.1”)
这个答案对我很有效,除了你能更新hasFeature url(删除额外的www。
var supported = document.implementation.hasFeature("http://w3.org/TR/SVG11/feature#Extensibility", "1.1"); –
var toStringFnc = ({}).toString;
Modernizr.addTest('svgforeignobject', function() {
return !!document.createElementNS &&
/SVGForeignObject/.test(toStringFnc.call(document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject')));
});