图像 Alt 和标题属性
我有一个客户讨厌浏览器中通过图像的 alt 和 title 属性显示的工具提示。他们要求将其删除。显然,这对于 SEO 和可访问性来说都是一个问题。
虽然可访问性对我来说并不是什么大事,但搜索引擎优化因素却很重要。我最初的想法是使用快速 JS 脚本删除图像的 alt 和 title 属性。有人看到这有什么问题吗?
I have a client who hates the tooltips shown in browsers by the alt and title attributes of images. They requested they be removed. Obviously this is an issue for both SEO and Accessibility.
While the accessibility thing is not a huge deal to me, the SEO factor is. My initial thoughts are to remove the alt and title attributes of the images with a quick JS script. Anyone see any issues with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
alt
和title
属性是两个不同的东西。alt
属性是出于可访问性原因而使用的,并且是 W3C 制定的标准所要求的。在美国,它也是第 508 条法律法规的一部分。alt
属性在旧版本的 Internet Explorer 中表现不佳,通过工具提示显示其内容。我知道 Internet Explorer 9 不再有这种行为。title
属性用于强制浏览器显示带有其内容的工具提示。我给您的建议是仅使用
alt
属性而不是title
属性。如果工具提示让客户非常恼火,建议他们将浏览器更新为更符合标准的浏览器。现代屏幕阅读器读取生成的 DOM。这意味着,如果您通过 JavaScript 删除标签,您不仅会在事后使代码失效,而且可能会伤害那些使用辅助技术访问该网站的人。
我强烈建议你不要这样做。
更多信息
Target 因
alt
属性而被起诉并达成和解:http://www.sitepoint.com/target-settles-accessibility-lawsuit-for-6-million/由于这个具有里程碑意义的案件,可以肯定地说,第 508 条不仅适用于联邦和政府网站。
The
alt
andtitle
attributes are two different things.The
alt
attribute is used for accessibility reasons and is required by the standards set by the W3C. In the United States, it's also part of the Section 508 laws and regulations. Thealt
attribute behaves poorly in older versions of Internet Explorer by showing it's contents via a tooltip. I know for a fact Internet Explorer 9 no longer has this behavior.The
title
attribute is used to force the browser in to showing a tooltip with it's contents.My advice to you is use the
alt
attribute exclusively instead of thetitle
attribute. Advise your client to update their browser to a more standards compliant browser if a tooltip irks them that much.Modern screen readers read the generated DOM. This means if you remove tags via JavaScript, you are not only invalidating your code after the fact, you are possibily hurting those who will visiting the site using assistive technology.
I highly recommend you don't do it.
More information
Target was sued and settled because of the
alt
attribute: http://www.sitepoint.com/target-settles-accessibility-lawsuit-for-6-million/Because of this landmark case, it's safe to say that Section 508 DOES NOT only apply to federal and government websites.
如果可访问性不是问题,那么我认为使用 JavaScript 删除内容没有任何问题。假设您可以使用 jQuery,我认为这是最简单的方法:
您还可以删除 onmouseover 事件中的标题内容,然后出于 SEO 的目的将其添加回 onmouseout 事件中。
If accessibility is not an issue, I see no issues using JavaScript to remove the content. Assuming you're OK with using jQuery, this is the easiest way in my opinion:
You could also remove the title content in the onmouseover event and then add it back on the onmouseout event for the sake of SEO.
在普通 JavaScript 中,您可以使用:
JS Fiddle 演示。
参考:
removeAttribute()
。In vanilla JavaScript, you could use:
JS Fiddle demo.
Reference:
removeAttribute()
at the Mozilla Developer Center.您应该考虑是否只想在某些情况下删除这些功能。我在日常业务中遇到了很多类似的想法,因为有些人不喜欢了解某些东西有什么好处,并且可能自己处理它们……
这让我想到最终添加一个 Greasemonkey 脚本,它提供了所需的功能,而不是通过可访问性等方式使网站变得更糟。至少它应该是一个额外的可配置选项,也许可以通过设置 cookie 或类似的东西。
也许您可以说服客户,让每个人都有自己的选择,并激活最佳搜索引擎优化和可访问性的默认设置,这比摆脱某些东西更好。
You should consider if you want to remove these features only under certain circumstances. I experience a lot of similar ideas in daily business, because some people do not like to understand what certain things a good for, and maybe handle them by themselves ...
... which brings me to the idea to eventually add a Greasemonkey script, which provides the desired functionality instead of worsening the website by means of accessibility, etc. At least it should be an additionally configurable option, maybe by setting a cookie or stuff like that.
Maybe you can convince the client it is a better than getting rid of something, to allow to make everyone the choice for their own, and activate the default settings for best SEO and accessibility.