javascript - Twitter Share button dynamic URL share -


i'm trying make custom twitter button grab page url of current page when clicked, change dependent on page appears on, not unlike default share button. however, unsure how pass page url button.

this have far jsfiddle

<style type="text/css" media="screen">  </style> <div id="social-share-container"> <div id="custom-tweet-button">  <a id="tweetshare" href="https://twitter.com/share?url="+encodeuricomponent(document.url); target="_blank">tweet     </a> </div> </div> 

it's bit hacked i'm pretty unfamiliar js.

this passes url , title simple pop-up box twitter share page:

<script language="javascript">     function tweetcurrentpage()     { window.open("https://twitter.com/share?url="+escape(window.location.href)+"&text="+document.title, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false; } </script>  <a class="tweet" href="javascript:tweetcurrentpage()" target="_blank" alt="tweet page">tweet page</a> 

if don't want open in popup box, can use instead of window.open:

window.location.href="https://twitter.com/share?url="+escape(window.location.href)+"&text="+document.title; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -