简体   繁体   English

头部内的锚标签?

[英]Anchor tag within head?

I want my website to become eligible for Google+ Direct Connect . 我希望我的网站有资格使用Google+ Direct Connect

So after googling a bit I found this Google Support page , which has since been edited. 所以在谷歌搜索后,我找到了这个谷歌支持页面 ,该页面已被编辑。
View Google Support page providing these instructions via WayBack Machine : 查看通过WayBack Machine提供以下说明的Google支持页面

You can directly link your website by inserting a small snippet of code on your website and then listing that website as your Google+ page's primary link in the About section of the profile. 您可以通过在您的网站上插入一小段代码直接关联您的网站,然后在该个人资料的“关于”部分中将该网站列为您的Google+信息页的主要链接。 For example, if your Google+ page's primary link is set to www.pagewebsite.com, you can create a bidrectional link by placing the following code snippet in the <head> tag of the site's HTML: 例如,如果您的Google+信息页的主要链接设置为www.pagewebsite.com,则可以通过将以下代码段放在网站HTML的<head>标记中来创建 bidrectional 链接:

<a href="https://plus.google.com/{+PageId}" rel="publisher" />

What gives? 是什么赋予了? An anchor tag within the head? 头部内的锚标签?

I thought only title/meta/link tags are allowed in the head. 我以为头部只允许使用title / meta / link标签。

Is it legal to place that above snippet in the head tag? 将上面的片段放在head标签中是否合法?

I think there's an error in Google's documentation and this should be a <link> -tag, like this: 我认为Google的文档中存在错误,这应该是<link> -tag,如下所示:

<link href="https://plus.google.com/{+PageId}" rel="publisher" />

You can test it on https://developers.google.com/structured-data/testing-tool/ if it works. 您可以在https://developers.google.com/structured-data/testing-tool/上进行测试,如果有效的话。 Include the <link> -tag into your website and see what Google detects with this tool. 在您的网站中加入<link> -tag,然后查看Google使用此工具检测到的内容。 There's a section "Publisher" where you can see if Google detects the correct information. 有一个“发布商”部分,您可以在其中查看Google是否检测到正确的信息。

I'm using <link> on my sites and Google detects the correct values. 我在我的网站上使用<link> ,Google会检测到正确的值。

An a element inside head is of course invalid according to any HTML specification. 根据任何HTML规范, heada元素当然是无效的。 I have no idea why Google tells you to do so, but presumably their software actually looks for such tags. 我不知道为什么谷歌会告诉你这样做,但可能他们的软件实际上是在寻找这样的标签。

What happens in practice in browsers is that the a tag implicitly closes the head element (you can see this if you look at the document tree in Developer Tools in a browser). 在浏览器中实际发生的事情是a标签隐式关闭head元素(如果你在浏览器中查看Developer Tools中的文档树,你可以看到这一点)。 This isn't as bad as it sounds, since the rest of elements meant to be in the head will still be processed normally. 这并不像听起来那么糟糕,因为其他要素在head仍然会被正常处理。 For example, even a title element works when placed inside body . 例如,即使title元素放置在body To tell truth, the division of a document into head and body is just a formality. 说实话,将文件划分为headbody只是一种形式。

The tag <a href="https://plus.google.com/{+PageId}" rel="publisher" /> will be taken as a start tag only, potentially causing naughty surprises, since the start of the document will then be inside a link (which might extend to the end of the document!). 标签<a href="https://plus.google.com/{+PageId}" rel="publisher" />将仅作为开始标记,可能会导致顽皮的意外,因为文档的开头将会然后进入一个链接(可能会扩展到文档的末尾!)。 Only if the page were served with an XML content type would the tag be taken as “self-closing”. 仅当页面以XML内容类型提供时,标记才会被视为“自动关闭”。 So if you have been forced into using such an element, at least write it with a real end tag; 因此,如果您被迫使用这样的元素,至少要用真正的结束标记写它;

<a href="https://plus.google.com/{+PageId}" rel="publisher"></a>

It will still be bad for accessibility and usability, since empty links may still participate in tabbing order etc. 它仍然不利于可访问性和可用性,因为空链接仍然可以参与Tab键顺序等。

Using link tag is the right (and valid!) way to go in the header: 使用链接标记是正确的(并且有效!)方式进入标题:

<link href="https://plus.google.com/{+PageId}" rel="publisher" />

If you stick with the verbatim anchor tag when following the instructions ( Link your brand page to your website ), then you'll be setting yourself up for something to blow up down the road. 如果您按照说明( 将您的品牌页面链接到您的网站 )坚持使用逐字锚标记,那么您将为自己设置一些东西以便在未来发展。

We just experienced it, in fact. 事实上,我们刚刚体验过它。 It seems starting with iOS 8.x, mobile Safari will see this anchor tag and move it (along with the code below it!) to the body. 它似乎从iOS 8.x开始,移动版Safari将看到这个锚标记并将其(以及它下面的代码!)移动到正文。 This broke a smart banner we had in place. 这打破了我们现有的智能旗帜。

We switched to using a link tag and verified that Google still detects the correct values. 我们切换到使用链接标记并验证Google仍然检测到正确的值。

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

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