Top Questions

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jul 31, 2016

    share on whatsapp using php

    <a data-text="Your message goes here.." data-link="http://dorcode.com" class="btn btn-sucess">Share</a>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    jQuery(document).ready(function() {
    
    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }
    };
    jQuery(document).on("click", '.whatsapp', function() {
            if( isMobile.any() ) {
    
                var text = jQuery(this).attr("data-text");
                var url = jQuery(this).attr("data-link");
                var message = encodeURIComponent(text)   " - "   encodeURIComponent(url);
                var whatsapp_url = "whatsapp://send?text="   message;
                window.location.href = whatsapp_url;
            } else {
                alert("Please share on mobile device");
            }
    
        });
    });
    </script>
     

Add Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.