Monday, March 31, 2014

Sharing functionality on Social Media using javascript

<html>
<head>
 <title>Social Media Sharing</title>
 <script type="text/javascript">
var url_1 = "https://www.google.co.in" ;
// Twitter Tweet
function goTwitter(title) {
var w = (screen.width-450)/2;
var h = (screen.height-450)/2;
var href = "http://twitter.com/share?text=" + encodeURIComponent(title)+"\n&media_url=http://www.fbrell.com/f8.jpg&url=" + encodeURIComponent(url_1);
var a = window.open(href, 'twitter', 'width=450,height=450,left='+w+',top='+h+',scrollbars=0');
if(a) { a.focus(); }
}
// Google Plus Share
function goGoogle(title, link) {
var w = (screen.width-450)/2;
var h = (screen.height-450)/2;
var href = "https://plus.google.com/share?url="+url_1;
var a = window.open(href, 'google', 'width=450,height=450,left='+w+',top='+h+',scrollbars=0');
if(a) { a.focus(); }
}
// Pinterest Share
function goPinterest(title, link) {
var w = (screen.width-450)/2;
var h = (screen.height-450)/2;
var href = "http://pinterest.com/pin/create/button/?url="+url_1+"&media=http://www.fbrell.com/f8.jpg&description=Google";
var a = window.open(href, 'Pinterest', 'width=750,height=450,left='+w+',top='+h+',scrollbars=0');
if(a) { a.focus(); }
}
// Facebook Share
function pstFaceBook(title,summary,image) {
var d = encodeURIComponent(title);
var image;
if(image!=""){
image = "&p[images][0]="+image;
}else{
image = "";
}
window.open('http://www.facebook.com/sharer.php?s=100&p[url]=' + encodeURIComponent(url_1)+"&p[title]=hello&p[summary]="+summary,"share",'resizable=no width=600 height=400');
}
</script>
</head>
<body>
<a href="javascript:pstFaceBook('Google','Google Home Page','http://www.fbrell.com/f8.jpg');" title="Facebook Share"><img src="http://ijustdid.org/wp-content/uploads/2012/11/Facebook-Share-Button-for-Mobile-300x132.jpg" width="100" height="50"alt="Facebook Share"></a>
<br/>
 <a href="javascript:goTwitter('Gogole');" title="Twitter"><img src="http://www.mediabistro.com/alltwitter/files/2011/05/tweet-button.jpg" width="100" height="70"alt="Twitter"></a>
 <br/>
 <a href="javascript:goGoogle('Name Collection','urlName');" title="Google Share"><img src="http://marketingland.com/wp-content/ml-loads/2013/11/new-gplus-share-button.png" width="100" height="30"alt="Google Share"></a>
 <br/>
 <br/>
 <a href="javascript:goPinterest('Name Collection','urlName');" title="Pinterest Pint"><img src="http://www.nextgenerationchiropractor.com/wp-content/uploads/2013/03/pinterest_pin-it_icon.png" width="100" height="30"alt="Pinterest Pint"></a>
</body>
</html>

No comments:

Post a Comment