How to share URL in Facebook Messenger through web ?


The following script enables you to share any link/URL in Facebook Messenger from webpage. We have used Facebook JavaScript SDK to achieve this.

The script opens a new window in desktop web browser that enables you to share any link to specified friend of yours. While in mobile browser, it opens up the Facebook Messenger app and the link can be shared easily with your friends.

Follow this video for complete guidance :

Full Source Code :

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="{YOUR_FACBOOK_APP_ID}&autoLogAppEvents=1" nonce="ywRETNx8"></script>

<link rel="stylesheet" type="text/css" href="">

<style type="text/css">
        background: #eef1f5;
        color: #0084ff;
        background: #fff;
        padding: 8px 20px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        text-decoration: none;
        background-color: #0084ff;
        color: white;

<a href="javascript:;" class="messenger-wrap" onclick="messengerShare()">
    <i class="fab fa-facebook-messenger"></i> 
    <span>Share on Messenger</span>

window.fbAsyncInit = function() {
        appId: '{YOUR_FACEBOOK_APP_ID}',
        xfbml: true,
        version: 'v2.9'

function isMobile() {
    const toMatch = [/Android/i, /webOS/i, /iPhone/i, /iPad/i, /iPod/i, /BlackBerry/i, /Windows Phone/i];
    return toMatch.some((toMatchItem) => {
        return navigator.userAgent.match(toMatchItem);

function messengerShare() {
    url = '';
    if (isMobile()) {
        window.location.href = "fb-messenger://share/?link=" + url;
    } else {
            method: 'send',
            link: url,
            redirect_uri: url


ALSO READ  PHP Source Code : Complete Facebook Chat Bot using PHP

Comments are closed.