选择文字转发到微博的JS

网络整理的选择文字转发到微博的JS,以备后用。

直接引入,把需要实现选择转发的标签块改掉就可以实现效果。

 1 var sinaImg = '<img style="display: none; cursor: pointer; position: absolute; width:26px; height:26px;" id="imgSinaShare" title="将选中内容分享到新浪微博" src="http://simg.sinajs.cn/blog7style/images/common/share.gif"/>';
 2 var qqImg = '<img style="display: none; cursor: pointer; position: absolute; width:25px; height:25px;" id="imgQqShare" title="将选中内容分享到腾讯微博" src="http://open.t.qq.com/images/resource/weiboicon32.png">';
 3 document.write(sinaImg);
 4 document.write(qqImg);
 5 var sinaImgShare = document.getElementById("imgSinaShare");
 6 var qqImgShare = document.getElementById("imgQqShare");
 7 var artMain = document.getElementById("share");  //需要实现选择转发到微博的标签块
 8 var $miniBlogShare = function(sinaShare, qqShare, eleContainer) {
 9     var eleTitle = document.getElementsByTagName("title")[0];
10     eleContainer = eleContainer || document;
11     var funGetSelectTxt = function() {
12         var txt = "";
13         if (document.selection) {
14             txt = document.selection.createRange().text;
15         } else {
16             txt = document.getSelection();
17         }
18         return txt.toString();
19     };
20     eleContainer.onmouseup = function(e) {
21         e = e || window.event;
22         var txt = funGetSelectTxt(),
23         sh = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
24         var left = (e.clientX - 40 < 0) ? e.clientX + 20: e.clientX - 40,
25         top = (e.clientY - 40 < 0) ? e.clientY + sh + 20: e.clientY + sh - 40;
26         if (txt) {
27             sinaShare.style.display = "inline";
28             sinaShare.style.left = left + "px";
29             sinaShare.style.top = top + "px";
30             qqShare.style.display = "inline";
31             qqShare.style.left = left + 30 + "px";
32             qqShare.style.top = top + "px";
33         } else {
34             sinaShare.style.display = "none";
35             qqShare.style.display = "none";
36         }
37     };
38     sinaShare.onclick = function() {
39         var txt = funGetSelectTxt(),
40         title = (eleTitle && eleTitle.innerHTML) ? eleTitle.innerHTML: "未命名页面";
41         if (txt) {
42             window.open('http://v.t.sina.com.cn/share/share.php?ralateuid=2719305811&title=' + txt + '→来自页面"' + title + '"的文字片段&url=' + window.location.href);
43         }
44     };
45     qqShare.onclick = function() {
46         var txt = funGetSelectTxt(),
47         title = (eleTitle && eleTitle.innerHTML) ? eleTitle.innerHTML: "未命名页面";
48         if (txt) {
49             window.open('http://v.t.qq.com/share/share.php?title=' + encodeURIComponent(txt + '→来自页面"' + title + '"的文字片段&url=' + window.location.href));
50         }
51     };
52 } (sinaImgShare, qqImgShare, artMain);

转载于:https://www.cnblogs.com/showblog/archive/2012/07/19/2599008.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值