动态Facebook Open Graph标签可能吗? [英] Dynamic Facebook Open Graph tags possible?
问题描述
我正在动态地更改我的< meta property =og:imagecontent =#>
和< meta property =og:titlecontent =#>
使用jQuery(以下)的标签。当我通过Chrome中的检查查看代码时,标签已成功更改。
I'm dynamically changing my <meta property="og:image" content="#">
and <meta property="og:title" content="#">
tags using jQuery (below). When I view the code via 'inspect' in Chrome, the tags have successfully been changed.
HTML:
<meta property="og:title" content="#">
<meta property="og:image" content="#">
jQuery:
$("meta[property='og:title']").attr("content", data.name);
$("meta[property='og:image']").attr("content", data.thumbnail.url);
但是 Facebook调试工具仍然显示 content =#
。我假设这是因为Facebook读取源代码,之后Javascript有机会替换内容。
But the Facebook debugger tool is still showing content="#"
for each. I'm assuming this is because Facebook reads the source code, before Javascript has a chance to replace the content.
有没有办法?
谢谢。
推荐答案
Facebook根本不解析JavaScript,使用动态Open Graph标签。显而易见,您只能在服务器上动态更改OG标签。
Facebook does not parse JavaScript at all, you can´t use dynamic Open Graph tags. It does not really make sense to change them on the fly anyway.
例如: https://yourdomain.com/dynamicogtags.php?title=xxx&description=xxx
<meta property="og:title" content="<?php echo $_GET['title'];?>">
不知道这是你想做什么,但URL看起来很丑陋。当然,重写会很好。
Not sure if that´s what you want to do though, the URL looks pretty ugly that way. Rewrite would be nice, of course.
这篇关于动态Facebook Open Graph标签可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!