admin管理员组文章数量:1419228
I'm creating a page which has a g+ share button, but I wanted to dynamically change the description of the content to share. to customize the share button I am using the snippet with Open Graph protocol.
The solution I tried was the following, but it did not work correctly:
<meta property="og:title" content="O Fabuloso Gerador De Lero Lero v3" />
<meta property="og:image" content="images/robot.png" />
<meta property="og:description" content="..." />
$('meta[property="og:description"]').attr('content',text);
var shareButtons = $('div:first','section.share-buttons');
shareButtons.html('');
shareButtons
.prepend('<a href="" class="twitter-share-button" data-text="' + text.trunc(120,true) + '" data-url="" data-lang="pt">Tweetar</a>')
.prepend('<div class="g-plus" data-action="share" data-href="=' + new Date().getTime() + '" data-annotation="bubble"></div>');
try {
window.twttr.widgets.load();
window.gapi.plus.go();
} catch(e) {}
but, the content of the description in share button is always the initial.
Anyone know how to make it work?
EDIT:
I had the same problem with the button twitte but managed to solve this:
shareButtons
.prepend('<a href="" class="twitter-share-button" data-text="' + text.trunc(120,true) + '" data-url="" data-lang="pt">Tweetar</a>');
window.twttr.widgets.load();
I'm creating a page which has a g+ share button, but I wanted to dynamically change the description of the content to share. to customize the share button I am using the snippet with Open Graph protocol.
The solution I tried was the following, but it did not work correctly:
<meta property="og:title" content="O Fabuloso Gerador De Lero Lero v3" />
<meta property="og:image" content="images/robot.png" />
<meta property="og:description" content="..." />
$('meta[property="og:description"]').attr('content',text);
var shareButtons = $('div:first','section.share-buttons');
shareButtons.html('');
shareButtons
.prepend('<a href="https://twitter./share" class="twitter-share-button" data-text="' + text.trunc(120,true) + '" data-url="http://goo.gl/1KHFM" data-lang="pt">Tweetar</a>')
.prepend('<div class="g-plus" data-action="share" data-href="http://lerolero.miguelborges./t=' + new Date().getTime() + '" data-annotation="bubble"></div>');
try {
window.twttr.widgets.load();
window.gapi.plus.go();
} catch(e) {}
but, the content of the description in share button is always the initial.
Anyone know how to make it work?
EDIT:
I had the same problem with the button twitte but managed to solve this:
shareButtons
.prepend('<a href="https://twitter./share" class="twitter-share-button" data-text="' + text.trunc(120,true) + '" data-url="http://goo.gl/1KHFM" data-lang="pt">Tweetar</a>');
window.twttr.widgets.load();
Share
Improve this question
edited Aug 14, 2012 at 18:32
Miguel Borges
asked Aug 4, 2012 at 0:22
Miguel BorgesMiguel Borges
7,6899 gold badges42 silver badges58 bronze badges
2
- Referring to your edit, Google+ does not have a parameter in their API to specify description text. You can view a plete list of their API parameters at this link: developers.google./+/plugins/+1button/#script-parameters – Kyle Macey Commented Aug 12, 2012 at 6:44
- google+ use the snippets for this. developers.google./+/plugins/snippet – Miguel Borges Commented Aug 14, 2012 at 18:38
2 Answers
Reset to default 2 +25The snippet for your page is generated by a server-side fetch of your page. The page fetcher does not execute JavaScript. This is why the changes that you've made to that element are not expressed in your share.
You can work around this issue using a get parameter and by specifying a target.
- Configure your page to accept the description as a GET paramater. For example, http://exmaple.?desc=foobar would cause your Open Graph tag to look something like this:
<meta property="og:description" content="foobar" />
- When you render your share link, share button or +1 button, target the page with the desired description specified using the GET parameter. For the share button, your markup may look like this:
<div class="g-plus" data-action="share" data-href="http://example./?desc=foobar"></div>
This will, however, impact counts. If you use this technique with the +1 button, each description will be considered a different page and the counts will accumulate separately.
I know that Facebook caches information for the description and other meta. It seems according to this link, Google + does as well. It seems like it's cached for an indefinite amount of time... This renders your situation nearly impossible, depending on how often you want to change the content. Either that, or wait a few days, and see if it does change. I'd like to note that Jenny is also correct, but after moving through that, you most likely still won't get desirable results.
本文标签: javascriptset text to google share buttonStack Overflow
版权声明:本文标题:javascript - set text to google+ share button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745302485a2652453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论