OpenGraph基于Ajax的网站 [英] OpenGraph on Ajax Based Website

查看:130
本文介绍了OpenGraph基于Ajax的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海兰!

这是我的另一个问题.. 我有一个网站,这是完全基于AJAX(哈希导航)。

Another Question from me.. I have a Website, which is Fully Ajax-Based (Hash Navigation).

有没有办法来刷新opengraph元标签的AJAX网站(使用JavaScript)? (当我点击一个链接,该标记,并有值应改变)

Is there a way to refresh opengraph meta-tags for ajax-based websites (With Javascript)? (When i Click a Link, the Tags, and there values should Change)

推荐答案

没有。开放图谱的标记必须在HTML页面,这是GETable纯HTTP present。

No. Open Graph markup must be present on HTML pages which are GETable with pure HTTP.

这是因为当用户与OG对象进行交互(比如,执行一个动作等),Facebook将在OG URL执行HTTP GET,并期望看到的标记返回OG标签。

This is because when a user interacts with an OG object (like, performs an action etc) Facebook will perform an HTTP GET on the OG URL, and expect to see OG tags returned in the markup.

解决方案是为每一个你的对象的规范网址。这些URL包含基本的HTML标记,包括OG标签。

The solution is to create canonical URLs for each of your objects. These URLs contain basic HTML markup including OG tags.

在请求这些URL,如果你看到一个包含facebookexternalhit传入的用户代理字符串,那么你呈现HTML。如果不这样做,你成为一个302重定向到你的AJAX网址。在您发布应指向规范的URL对象的AJAX的网址,你喜欢按钮和任何OG行动

On requests to these URLs, if you see the incoming useragent string containing 'facebookexternalhit' then you render the HTML. If you don't, you serve a 302 which redirects to your ajax URL. On the ajax URLs, your like buttons and any OG actions you publish should point to the canonical URL object

例如:

作为一个用户,我在 http://yoursite.com/#!/artists/monet 。我点击一个像按钮,或者当您发布的动作应该是一个web hittable规范网址为对象发布的行动,但类似按钮的href参数或对象的URL - 在这种情况下,可能的http://yoursite.com/artists/monet

As a user, I'm on http://yoursite.com/#!/artists/monet. I click a like button, or publish an action, but the like button's href parameter, or the URL of the object when you post the action should be a web hittable canonical URL for the object - in this case, perhaps http://yoursite.com/artists/monet

在使用浏览器的用户点击 http://yoursite.com/artists/monet 你应该重定向到<一个HREF =htt​​p://yoursite.com/#!/artists/monet> http://yoursite.com/#!/artists/monet ,但如果输入的用户代理说,这是Facebook的刮刀你,只是返回的标记从而重新presents画家莫奈。

When a user using a browser hits http://yoursite.com/artists/monet you should redirect them to http://yoursite.com/#!/artists/monet, but if the incoming useragent says it is Facebook's scraper, you just return markup which represents the artist Monet.

有关现实世界的例子,看到的Deezer,RDIO和莫古都使用这种设计模式谁。

For real world examples, see Deezer, Rdio and Mog who all use this design pattern.

这篇关于OpenGraph基于Ajax的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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