admin管理员组

文章数量:1353646

I have a site that dynamically updates the URL hash as the user navigates through it (it's a Backbone.js app and I'm using pushState).

I'd like the user to be able to tweet the full URL, including the hash.

I'm using the Twitter share button, but it seems to only share the basic URL path, not the hash, which is quite important:

<a href="" class="twitter-share-button">Tweet</a>

Any ideas for how I can let users share the hash as well?

Thanks for your help.

I have a site that dynamically updates the URL hash as the user navigates through it (it's a Backbone.js app and I'm using pushState).

I'd like the user to be able to tweet the full URL, including the hash.

I'm using the Twitter share button, but it seems to only share the basic URL path, not the hash, which is quite important:

<a href="https://twitter./share" class="twitter-share-button">Tweet</a>

Any ideas for how I can let users share the hash as well?

Thanks for your help.

Share Improve this question asked Apr 25, 2012 at 8:22 RichardRichard 33k30 gold badges111 silver badges146 bronze badges 3
  • 2 You are using pushState, so there shouldn't be a hash unless the user uses an old browser. – ThiefMaster Commented Apr 25, 2012 at 8:23
  • 1 Sure, but I need to support users with old browsers... – Richard Commented Apr 25, 2012 at 8:42
  • I think this may be the best answer: stackoverflow./questions/9215806/… I hope Twitter add an option to include this by default. – Richard Commented Apr 30, 2012 at 21:45
Add a ment  | 

2 Answers 2

Reset to default 13

the trick is to replace the hash sign with its html encoded character which is : %23

Does that button use the referer? If yes, you are out of luck - the hash is never sent to the server.

However, when using pushState you don't need a hash unless the user's browser is too old - but for everyone with a recent browser it should work fine as the referer will be whatever is currently used in the address bar.

本文标签: javascriptTwitter share button share hash part of URLStack Overflow