最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實(shí)現(xiàn)將選中內(nèi)容分享到新浪或騰訊微博

 更新時間:2015年12月16日 16:01:09   投稿:lijiao  
這篇文章主要介紹了js實(shí)現(xiàn)將選中內(nèi)容分享到新浪或騰訊微博,需要的朋友可以參考下

微博如火如荼,大家都選擇用微博帶來社會化流量,順便推廣產(chǎn)品和網(wǎng)站,幾乎所有的網(wǎng)站都有分享到代碼,但是還有一種更快捷的分享方式,javascript就可以實(shí)現(xiàn)將選定內(nèi)容輕松分享到新浪微博和騰訊微博,效果圖如下:

將選中的內(nèi)容分享到新浪微博,騰訊微博實(shí)現(xiàn)js代碼如下:

<STYLE>
.img_sina_share {
DISPLAY: none; CURSOR: pointer; POSITION: absolute
}
.img_qq_share {
DISPLAY: none; CURSOR: pointer; POSITION: absolute
}
</STYLE>
<IMG
class=img_sina_share id=imgSinaShare title=將選中內(nèi)容分享到新浪微博
src="http://www.phpddt.com/usr/themes/dddefault/images/sina.gif">
<IMG
class=img_qq_share id=imgQqShare title=將選中內(nèi)容分享到騰訊微博
src="http://www.phpddt.com/usr/themes/dddefault/images/qq.gif">
<SCRIPT>
var eleImgShare = document.getElementById("imgSinaShare"); /
var eleImgShare2 = document.getElementById("imgQqShare"); 
 
var $miniBlogShare = function(eleShare,eleShare2,eleContainer) { //實(shí)現(xiàn)方法
var eleTitle = document.getElementsByTagName("title")[0];
eleContainer = eleContainer || document;
var funGetSelectTxt = function() { //獲取選中文字
var txt = "";
if(document.selection) {
txt = document.selection.createRange().text; // IE
} else {
txt = document.getSelection();
}
return txt.toString();
};
eleContainer.onmouseup = function(e) { //限定容器若有文字被選中
e = e || window.event;
var txt = funGetSelectTxt(), sh = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
var left = (e.clientX - 40 < 0) ? e.clientX + 20 : e.clientX - 40, top = (e.clientY - 40 < 0) ? e.clientY + sh + 20 : e.clientY + sh - 40;
if (txt) {
eleShare.style.display = "inline";
eleShare.style.left = left + "px";
eleShare.style.top = top + "px";
eleShare2.style.display = "inline";
eleShare2.style.left = left + 30 + "px";
eleShare2.style.top = top + "px";
} else {
eleShare.style.display = "none";
eleShare2.style.display = "none";
}
};
eleShare.onclick = function() { //點(diǎn)擊新浪微博圖標(biāo)
var txt = funGetSelectTxt(), title = (eleTitle && eleTitle.innerHTML)? eleTitle.innerHTML : "未命名頁面";
if (txt) {
window.open('http://v.t.sina.com.cn/share/share.php?title=' + txt + ' ' + title + '&url=' + window.location.href + '','微博分享','width=700, height=580, top=320, left=180, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');
}
};
eleShare2.onclick = function() { //點(diǎn)擊騰訊微博圖標(biāo)
var txt = funGetSelectTxt(), title = (eleTitle && eleTitle.innerHTML)? eleTitle.innerHTML : "未命名頁面";
if (txt) {
window.open( 'http://v.t.qq.com/share/share.php?title=' + encodeURIComponent(txt + ' ' + title + ' ') + '&url=' + window.location.href + '','微博分享','width=700, height=580, top=320, left=180, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');
}
};
}(eleImgShare,eleImgShare2);
</SCRIPT>

將以上的代碼黏貼到你想要進(jìn)行內(nèi)容分享的頁面,要注意的是,最好不要放在header.php或者footer.php這樣網(wǎng)站所有內(nèi)容都進(jìn)行分享,而我只是放在文章頁面!

以上就是js實(shí)現(xiàn)將選中內(nèi)容分享到新浪或騰訊微博的詳細(xì)代碼,希望對大家學(xué)習(xí)javascript程序設(shè)計有所幫助。

相關(guān)文章

最新評論

洪江市| 南溪县| 米泉市| 安陆市| 富宁县| 龙胜| 三门峡市| 吉木乃县| 屯门区| 龙州县| 电白县| 桃源县| 泰安市| 太白县| 济宁市| 门源| 田林县| 道孚县| 孙吴县| 聂荣县| 清河县| 肥东县| 竹溪县| 屏东市| 龙游县| 城口县| 牟定县| 临城县| 唐山市| 昌黎县| 康乐县| 江油市| 聂拉木县| 宜兰市| 荣成市| 左权县| 泰州市| 安泽县| 云龙县| 临安市| 若羌县|