如何使用html在标题栏中添加图像?

pro*_*911 12 html5 wamp

<DOCTYPE! HTML>
<html>
<head>
    <title>Login</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
    some text

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我在浏览器的新标签栏中添加图像所编写的代码.但这不起作用.我也在使用wamp服务器,如果wamp可能会导致问题.

Dav*_*esh 15

根据维基百科,最兼容浏览器的咒语是:

<link rel="shortcut icon" href="favicon.ico" />
Run Code Online (Sandbox Code Playgroud)

之后,您只需担心您的浏览器是否实际下载了该图标.服务器日志说什么?你检查过你的浏览器网络调试控制台吗?


Mir*_*rco 6

W3C说:

<!DOCTYPE html 
      PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" 
      type="image/png" 
      href="http://example.com/myicon.png">
[…]
</head>
[…]
</html>
Run Code Online (Sandbox Code Playgroud)

见http://www.w3.org/2005/10/howto-favicon

但请记住:有些浏览器需要一段时间来识别有一个图标 - 尝试删除cookie并重新打开您的网站!(并确保图标在路径:))