我目前有一个网站,在我正在创建的社交网络小部件上包含 Google 分享按钮(以及 Facebook 和 Twitter)。我想做的是能够在 textarea 字段中输入一些文本,然后按下“发送”按钮,文本将共享到 Google+ 用户的墙上(我已经有 Facebook 和 Twitter 帖子工作)。现在我知道 Google+ 的共享按钮有一个名为“data-prefilltext”的字段,这是我尝试使用来自 textarea 的消息设置的字段。当我按下“发送”按钮时,我可以看到“数据预填充文本”字段值发生变化,但在弹出窗口中,我没有看到文本变化。下面是代码:
HTML:
<div id="googleplus-selector" title="App is what's new! Share it with your circles in Google+"
class="social-networking-icons g-interactivepost"
data-contenturl="http://plus.google.com/pages/"
data-contentdeeplinkid="/pages"
data-clientid="clientid.apps.googleusercontent.com"
data-scope="https://www.googleapis.com/auth/youtube.readonly"
data-cookiepolicy="single_host_origin"
data-prefilltext="Share App with your circle of friends now!"
data-calltoactionlabel="TRY_IT"
data-calltoactionurl="http://plus.google.com/pages/"
data-calltoactiondeeplinkid="/pages/create"
data-href="http://mysiteurl">
<div class="widget-mask"></div>
</div>
Javascript/jQuery:
var textElement = $('#social-message-text');
var text = textElement.val();
$('#google-plus-share-button').attr('data-prefilltext', text);
就像我说的,在检查 Firebug 或 Google 的开发者控制台中的元素时,我可以看到属性值的变化,但是当打开 Google Share 弹出窗口时,文本的变化不会反映出来。
任何帮助将不胜感激,因为我现在有点难过。提前感谢大家。