Post on Twitter using JavaScript

HTML Block:
<div> <a href="javascript: void(0)" onclick="TwitterPopup('https://twitter.com/share?url= YourSiteURL&text=TextToPostOnTwitter')" ></a></div>

JavaScript Block:
function TwitterPopup(url) 
{
        var width  = 500;
        var height = 300;
        var left   = (screen.width  - width)/2;
        var top    = (screen.height - height)/2;
        var params = 'width='+width+', height='+height;
        params += ', top='+top+', left='+left;
        params += ', directories=no';
        params += ', location=no';
        params += ', menubar=no';
        params += ', resizable=no';
        params += ', scrollbars=no';
        params += ', status=no';
        params += ', toolbar=no';

        var twtPopupTitle = 'Post on Twitter';

        if (navigator.appName == 'Microsoft Internet Explorer')
        {
               twtPopupTitle = null;
        }  

        var newwin =  window.open(url, twtPopupTitle, params);

        if (window.focus) {
               newwin.focus();    
        }
        return false;
}
            
!function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) 
? 'http' : 'https'; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = p + '://platform.twitter.com/widgets.js'; fjs.parentNode.insertBefore(js, fjs); } } (document, 'script', 'twitter-wjs');

1 comment:

  1. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. 统计代写

    ReplyDelete