How to Share Link to Facebook App on Page Tab

It is often the case that you create a Facebook application and put it on a Facebook page tab. Then you want to share a link to that tab and it appears that the image the Facebook automatically gets is the page tab image. It does not matter if you have set the corrent OpenGraph (og:) tags, it still gets the page tab image.

Then you have 2 choices – you either delete the automatically extracted image using the X in the upper right corner and upload you own, or you share a link to the Canvas Page (set in the Facebook Developers portal in the application management interface, then Settings -> Facebook Canvas) and automatically redirect the user to the Facebook Page Tab using this JavaScript, jQuery and this code:

$( document ).ready(function(){
    if (top == self || document.referrer === "https://apps.facebook.com/your_app_namespace/"){
        top.location = "https://www.facebook.com/your_page/app_id";
    }
});

That way all users that have landed on the canvas url (the url on which your app is hosted) and on canvas page url will be redirected to the page tab.