html [html] [jscript]社交分享示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html [html] [jscript]社交分享示例相关的知识,希望对你有一定的参考价值。
<script>
var FB_APP_ID = "xxx";
var BITLY_LOGIN = 'xxx';
var BITLY_API_KEY = 'xxx';
var BITLY_URL = 'http://api.bitly.com/v3/shorten?callback=?';
var clickevent = '';
if ('ontouchstart' in document.documentElement) {
clickevent = 'touchend';
overevent = 'touchstart';
} else {
clickevent = 'click';
overevent = 'mouseover';
}
$(document).ready(function () {
/* bind click/touch events */
$('#jf-facebook-btn').bind(clickevent, function () {
shareButtonClick('facebook');
});
$('#jf-twitter-btn').bind(clickevent, function () {
shareButtonClick('twitter');
});
$('#jf-email-btn').bind(clickevent, function () {
shareButtonClick('email');
});
/* end bind click/touch events */
/* FB init C.O.*/
FB.init({ appId: FB_APP_ID, status: true, cookie: true });
/* End FB init C.O.*/
});
function shareButtonClick(shareType) {
var br = '\r\n';
var p = '\r\n\r\n';
var appName = 'Question of the Day | Just Facts';
var caption = 'JUSTFACTSDAILY.COM'; //'be informed, not just opinionated.';
var quizTitle = QUIZ_TOPIC.toLowerCase();
var descr = 'Today\'s question of the day from Just Facts is about ' + quizTitle + '.';
var websiteLink = 'http://www.justfactsdaily.com/question?question=' + QUESTION_ID;
var iOSAppLink = '<a href="https://itunes.apple.com/app/justfacts/id663124707" target="_blank">iOS App</a>';
var appIcon = 'http://m.admin.justfactsdaily.com/gfx/social-icon-rounded-200.png';
var encourage = 'See if you can answer this question correctly.';
var url = '';
var question = $('#jf-question').text();
var options = '';
$('input[name="options"]').each(function() {
options += '- ' + $(this).next('label:first').text() + br;
});
switch (shareType) {
case 'facebook':
descr += ' ' + encourage;
window.open(
'http://www.facebook.com/dialog/feed?'
+ 'app_id=' + FB_APP_ID
+ '&name=' + appName
+ '&picture=' + appIcon
+ '&display=popup'
+ '&caption=' + caption
+ '&link=' + htmlEncode(websiteLink)
+ '&description=' + htmlEncode(question)
+ '&redirect_uri=' + htmlEncode(websiteLink)
);
break;
case 'twitter':
var longUrl = htmlEncode(websiteLink);
var twitterUrl = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(longUrl);
twitterUrl += '&text=' + encodeURIComponent(descr);
window.open(twitterUrl, '_blank');
break;
case 'email':
//*** setup URL text.
url += ' See if you can answer this question correctly.' + br;
url += websiteLink;
//*** setup Email
var emailStr = '';
var emailSubject;
var emailBody = '';
emailSubject = 'Question about ' + quizTitle;
emailBody += descr + p;
emailBody += question + p;
emailBody += options + br;
emailBody += url;
emailStr += 'mailto:';
emailStr += '?';
emailStr += 'subject=' + encodeURIComponent(emailSubject);
emailStr += '&';
emailStr += 'body=' + encodeURIComponent(emailBody);
window.open(emailStr, '_blank');
break;
}
}
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
</script>
<!DOCTYPE html>
<html>
<head>
<script src='http://connect.facebook.net/en_US/all.js'></script>
</head>
<body>
<div id="jf-share" class="jf-share">
<h2>Test Your Friends!</h2>
<div class="jf-share-buttons">
<div id="jf-facebook-btn" class="jf-one-third"></div>
<div id="jf-twitter-btn" class="jf-two-third"></div>
<div id="jf-email-btn" class="jf-last-third"></div>
</div>
</div>
<!-- Facebook -->
<div id="fb-root"></div>
<!-- /Facebook -->
</body>
</html>
以上是关于html [html] [jscript]社交分享示例的主要内容,如果未能解决你的问题,请参考以下文章