Reputation: 2063
Q: how to pass the url like this to facebook.
https://www.facebook.com/sharer.php?t=XBOX&u=http://aaa.com/#/project/xbox-branding
when I passed this url to facebook, facebook modify the url to
http://aaa.com/project/xbox-branding
in the facebook's post my shared url can't link to correct url.
Upvotes: 1
Views: 10187
Reputation: 28995
Always encode the url to escape special characters.
In js,
'https://www.facebook.com/sharer.php?t=XBOX&u=' + encodeURIComponent('http://aaa.com/#/project/xbox-branding');
In php,
'https://www.facebook.com/sharer.php?t=XBOX&u='.urlencode('http://aaa.com/#/project/xbox-branding');
Upvotes: 0
Reputation: 2063
ans : change # to %23 in the url. e.g http://aaa.com/%23/project/......
Upvotes: -1
Reputation:
<a href="http://www.facebook.com/share.php?t=XBOX&u=http://aaa.com/%23/project/xbox-branding/" onclick="return fbs_click()" target="_blank">CLICK ME</a>
<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script>
Upvotes: 2
Reputation: 39704
encode #
to %23
, you can do this with urlencode()
https://www.facebook.com/sharer.php?t=XBOX&u=http://aaa.com/%23/project/xbox-branding
but you should encode the full redirect URL like this:
https://www.facebook.com/sharer.php?t=XBOX&u=http%3A%2F%2Faaa.com%2F%23%2Fproject%2Fxbox-branding
Upvotes: 2