简体   繁体   English

在HTML源代码中查找所有空链接(包含href =“ x”的空标签)的最通用方法是什么?

[英]What's the most general way to find all empty links (empty tags containing an href=“x”) in HTML source?

I scanned the homepage of my website through a accessibility problem scanner ; 我通过无障碍问题扫描仪扫描了网站主页; A tool I use to find problems in my markup and information-presentation, in the context of web accessibility . 网络可访问性的背景下,我用来查找标记和信息表示问题的工具。

Using the WAVE report tool , I found two problems: Both of which are "empty links". 使用WAVE报告工具 ,我发现了两个问题:两者都是“空链接”。

Maybe I missed that but I don't get from the tool what these links are and how to find them so I would delete them via my WordPress page builder ( Elementor ), the tool with which I created the markup for this site. 也许我错过了,但是我无法从工具中获得这些链接的含义以及如何找到它们,因此我将通过我的WordPress 页面构建器Elementor )删除它们,我使用该工具为该网站创建了标记。

An accessibility specialist told me that doing CTRL+F then searching in source for say <a href=""></a> isn't efficient as there can many biases and AFAIK an empty link doesn't even have to be a a tag. 一位可访问性专家告诉我,执行CTRL + F然后在源代码中搜索<a href=""></a>效率不高,因为可能存在很多偏差,并且AFAIK的空链接甚至不必a标签。

My question is how to find empty links, do you know a general, reliable technique I could use to gather reasonable data about these links and remove them. 我的问题是如何找到空链接,您知道我可以用来收集有关这些链接的合理数据并将其删除的一般可靠技术吗?

When using the WAVE tool there is a tiny (which is why you won't have seen it) green tab sticking up from the bottom called <code> . 使用WAVE工具时,有一个很小的绿色标签(这就是为什么您不会看到它)从底部伸出的绿色标签叫<code>

Click on an item you failed on and then click on this tab and it will show the affected code in the bottom pane that appears. 单击您失败的项目,然后单击此选项卡,它将在出现的底部窗格中显示受影响的代码。 It will also attempt to highlight the affected item for you but this isn't always clear (which is ironic given that this is an accessibility tool!!) 它还会尝试为您突出显示受影响的项目,但这并不总是很清楚(具有讽刺意味的是,这是一个可访问性工具!!)

A reliable way to find the links is difficult because it includes SVGs, icons etc. etc. as empty, but as a general rule a script that searches for all <a> tags and then gathers their textContent (or .text() in jQuery I think) will work (if textContent is empty then it is likely a problem, you might get a few false positives but it should make life easy). 查找链接的可靠方法很困难,因为它包含空的SVG,图标等,但是作为一般规则,脚本会搜索所有<a>标签,然后在jQuery中收集其textContent (或.text())我认为)会起作用(如果textContent为空,则可能是一个问题,您可能会得到一些误报,但这应该使生活变得轻松)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM