在SVG中插入favicon链接标记的正确方法[重复](Correct way to insert favicon link tag in SVG [duplicate])
这个问题在这里已有答案:
纯SVG文件可以指定一个Favicon.ico吗? 1个答案插入指向favicon的链接标记的正确方法是什么? 我尝试了以下但W3C Validator报告元素“xhtml:link”undefined 。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <title>De mægtige vikinger</title> <defs> <xhtml:link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> </defs> </svg>This question already has an answer here:
Can pure SVG document specify a Favicon.ico? 1 answerWhat is the correct way to insert a link tag that points to favicon? I've tried the following but the W3C Validator reports element "xhtml:link" undefined.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <title>De mægtige vikinger</title> <defs> <xhtml:link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> </defs> </svg>最满意答案
验证器本身并没有错,因为你拥有的不是纯svg,它是svg加上一些xhtml而验证器没有这样的配置。 我看到它的方式有两种选择:
接受这就是现在的浏览器,并为此用例创建一个新的验证配置文件/自定义DTD。 通过更改标记并删除xml标头并设置<!DOCTYPE html> ,将svg作为html5传递出去。 然后你可以像往常一样把链接放在头部。 请注意,这可能意味着您将无法将该文件作为svg引用(因为它是html),因此请务必在您定位的所有浏览器中进行测试。The validator isn't wrong per se, because what you have isn't pure svg, it's svg plus some xhtml and the validator has no such configuration. The way I see it you have two options:
accept that this is how it is in browsers right now, and create a new validation profile / custom DTD for this use-case. pass the svg off as html5 instead, by changing the markup and removing the xml header and setting <!DOCTYPE html>. Then you can put the link as usual in the head section. Note that this may mean you won't be able to reference the file as an svg (since it's then html), so be sure to test in all browsers you target.更多推荐
发布评论