在SVG中插入收藏夹链接标记的正确方法 [英] Correct way to insert favicon link tag in SVG

查看:65
本文介绍了在SVG中插入收藏夹链接标记的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入指向网站图标的链接标签的正确方法是什么? 我尝试了以下操作,但是 W3C验证程序报告了未定义元素"xhtml:link" >.

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,并且验证器没有这样的配置.从我的角度来看,您有两种选择:

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:

  1. 接受当前的浏览器情况,并为此用例创建一个新的验证配置文件/自定义DTD.
  2. 通过更改标记并删除xml标头并设置<!DOCTYPE html>,将svg改为html5.然后,您可以像往常一样将链接放在头部.请注意,这可能意味着您将无法以svg形式引用该文件(因为它是html),因此请确保在您定位的所有浏览器中进行测试.
  1. accept that this is how it is in browsers right now, and create a new validation profile / custom DTD for this use-case.
  2. 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.

这篇关于在SVG中插入收藏夹链接标记的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆