在SVG中插入favicon链接标记的正确方法[重复](Correct way to insert favicon link tag in SVG [duplicate])

编程入门 行业动态 更新时间:2024-10-27 02:17:43
在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 answer

What 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.

更多推荐

本文发布于:2023-08-07 08:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   正确   链接   方法   SVG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!