1.首先在网页中引用js
2.在head下面添加如下代码
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<%--<meta name="twitter:title" content="@ViewBag.Title" />
<meta name="twitter:description" content="@ViewBag.Description" />
<meta name="twitter:image" content="@ViewBag.ShareImg" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:url" content="当前分享的链接--可要可不要" />
<meta property="og:image" content="@ViewBag.ShareImg" />
<meta property="og:locale" content="en-US" />
<meta property="og:type" content="website" />
<meta property="og:url" content="当前分享的链接--可要可不要" /> --%>
3.分享文章的js
<%--分享facebook文章js--%>
<script type="text/JavaScript">
function popupwindow(url, title, w, h) {
wLeft = window.screenLeft ? window.screenLeft : window.screenX;
wTop = window.screenTop ? window.screenTop : window.screenY;
var left = wLeft + (window.innerWidth / 2) - (w / 2);
var top = wTop + (window.innerHeight / 2) - (h / 2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}
window.onload = function () {
document.getElementById('share_button').onclick = function () {
var shareUrl = "http://www.facebook.com/sharer/sharer.php?u=" + facebook.baseURI + "";
popupwindow(shareUrl, 'Facebook', 600, 400);
}
}
</script>
4.div中写如下代码 <span id="share_button"> <img src="../xq_files/facebook.png" /></span>
黄色字体对应div中span的id 红色表示你要给的参数(我这里是给的自己网站文章的链接)