SVG报错error on line 39 at column 26: Namespace prefix xlink for href on script is not defined

时间:2023-03-09 19:39:02
SVG报错error on line 39 at column 26: Namespace prefix xlink for href on script is not defined

转自:http://*.com/questions/3561270/error-on-line-39-at-column-26-namespace-prefix-xlink-for-href-on-script-is-not

SVG写入image标签时,发现在google和火狐上无法显示,且报错: Namespace prefix xlink for href on script is not defined

后经查询,找到了解决办法:

在命名空间上添加:

xmlns:xlink=http://www.w3.org/1999/xlink

实例:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" > <circle cx="" cy="" r="" stroke="black"
stroke-width="" fill="red"/> <image xlink:href="happy-every-day.jpg" width="" height="" /> </svg>

其中红色的命名空间是使google、火狐浏览器兼容SVG的,蓝色的部分是image标签适应google或火狐浏览器的。