Facebook Share Button in Frameset

I spent a lot of time today figuring out how to get the Facebook Share Button to work in a frameset and display the frameset Url and Title instead of the Url and Title of the frame the button was placed in. I thought this should be very easy but it took me quite some time to fnd an ok solution, probably because I’m not that good at Javascript. If you know of a better solution please let me know.

Facebook Share Button original code:

<a name=”fb_share” type=”icon_link” href=”http://www.facebook.com/sharer.php”>Share</a>
<script src=”http://static.ak.fbcdn.net/connect.php/js/FB.Share” type=”text/javascript”></script>

To set url and page title to that of frameset add this after above code:

<script>
document.getElementsByName(‘fb_share’)[0].setAttribute(‘href’, ‘http://www.facebook.com/sharer.php?u=’ + escape(parent.location.href) + ‘&t=’ + escape(parent.document.title));
</script>

One problem with directing Facebook direct to the frameset url is that it cannot find Content Summary and Image but I think this can be fixed by adding some meta tags as described in Facebooks documentation.

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *