To create a custom twitter button you need to encode some strings and insert a few lines of JavaScript. This is how it can be done:
HTML code:
<a id="twitterLink" target="_blank">
<img src="./images/twitter.png" alt="Twitter button" />
</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> |
<a id="twitterLink" target="_blank">
<img src="./images/twitter.png" alt="Twitter button" />
</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
JavaScript code:
var url = window.location.href.split('?')[0];
var twitterUrl=encodeURIComponent(url);
var twitterText=encodeURIComponent('Hello World:');
var twitterLink='https://twitter.com/share?text='+twitterText+'&url='+twitterUrl+'&count=none';
document.getElementById('twitterLink').href=twitterLink; |
var url = window.location.href.split('?')[0];
var twitterUrl=encodeURIComponent(url);
var twitterText=encodeURIComponent('Hello World:');
var twitterLink='https://twitter.com/share?text='+twitterText+'&url='+twitterUrl+'&count=none';
document.getElementById('twitterLink').href=twitterLink;