Search code examples
javascriptsocial-networking

Social Media Sharing Cutting Off Hashtag


I'm trying to share pages that have a list of boxes where when you click on it, it shows content for that box. When I click the icon to share, say on Facebook, I see that it gets the url correctly:

https://www.facebook.com/sharer/sharer.php?u=http://localhost:50443/students/res-mock2.aspx#transferable-skills

But the link that actually gets shared is everything up to the #transferable-skills

I use encodeURI() to encode the hashtag.

Any suggestions as to what might be causing this?


Solution

  • I use encodeURI() to encode the hashtag.

    That doesn't encode the hashtag. Use encodeURIComponent instead:

    https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Flocalhost%3A50443%2Fstudents%2Fres-mock2.aspx%23transferable-skills