我有一个像这样Twitter分享按钮不使用自定义URL或文本
= link_to "https://twitter.com/share", class: "twitter-share-button", data: { url: "https://google.com", text: hack.body, via: "GhettoLifeHack_", hashtags: "ghettolifehack" } do
= image_tag "Tweet", alt: "Social Twitter tweet button"
而且不管我多么更改数据的URL值的链接,鸣叫预确认页面始终预填充的鸣叫表单字段与引用页面的网址,而不是我指定的网址。它也会忽略我的自定义数据文本。
这是怎么发生的?
我也有这样的精缩脚本
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
,我从这里https://about.twitter.com/resources/buttons#tweet 删除了该脚本似乎并没有改变任何东西。
编辑:在尝试直接使用:'data-url'
属性时,输出html是相同的。
我正在测试硬编码的字符串和动态生成的URL在同一时间。首先是动态的。
<a class="twitter-share-button" href="https://twitter.com/share" data-via="GhettoLifeHack_" data-url="http://localhost:3000/hacks/1" data-text="asdf comment body" data-hashtags="ghettolifehack">
<img src="/images/Tweet" alt="Tweet" title=""></img>
</a>
第二个是硬编码字符串
<a class="twitter-share-button" href="https://twitter.com/share" data-via="GhettoLifeHack_" data-url="httpL//google.com" data-text="custom text" data-hashtags="ghettolifehack">
<img src="/images/Tweet" alt="Tweet" title=""></img>
</a>
我的发展和生产测试。两者都具有相同的行为,用引用url预填充推文表单,而不是指定的url和文本。
这适用于Chrome浏览器我,但不能在Firefox 32
如果你直接给自定义属性,如 = link_to“https://twitter.com/share”,class :“twitter-share-button”,:'data-url'=>'url',:'data-text'=> hack.body – addicted20015 2014-09-27 20:01:22
修改数据url和数据文本属性不会成为占位符或pre如前所述,在预推文页面中填充表单文本。你是在谈论使用直接字符串散列而不是散列内散列符号?当我使用浏览器检查器时,我已经看到了正确显示的属性。如果将相应的语法改为您所说的使其起作用,那么这意味着散列内散列语法不起作用......在这一点上,我将翻转我的表,因为这没有任何意义。 – ahnbizcad 2014-09-27 20:10:30
也,我不认为我应该做':'data-url''。如果有的话,它应该是':data-url'。 – ahnbizcad 2014-09-27 20:13:27