Rocco The Taco
Rocco The Taco

Reputation: 3797

Facebook encodeURIComponent onClick event

How do I change the a +encodeURIComponent(location.href) to use a specific URL instead of the current page?

I tried this with no luck:

onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='http://www.domain.com/tell-a-friend/','facebook-share-dialog','width=626,height=436'); return false;"

This is the original that works fine from Facebook API.

<a href="#" 
  onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return false;">
  Share on Facebook
</a>

Upvotes: 0

Views: 2000

Answers (1)

dljve
dljve

Reputation: 545

You have a misplaced quote in your code:

onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='http://www.domain.com/tell-a-friend/','facebook-share-dialog','width=626,height=436'); return false;"
                                                                   ^

Change it to:

onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=http://www.domain.com/tell-a-friend/','facebook-share-dialog','width=626,height=436'); return false;"

Upvotes: 1

Related Questions