Thu Ra
Thu Ra

Reputation: 2063

how to pass the url like this to facebook

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

Answers (4)

Jashwant
Jashwant

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

Thu Ra
Thu Ra

Reputation: 2063

ans : change # to %23 in the url. e.g http://aaa.com/%23/project/......

Upvotes: -1

user1317647
user1317647

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

Mihai Iorga
Mihai Iorga

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

Related Questions