html 分享到新浪微博,JQuery用鼠标选文字来发新浪微博

最近注意到新浪博客有个小功能,就是当鼠标选中一段文字时会浮现一个小图片,点击这个图片可以把选中内容发送到新浪微博,一时兴起昨晚就写了一个Demo玩了一下,代码超简单,没优化,有兴趣的朋友可以自己改进。

原理很简单,先获得鼠标选中文字,然后调用新浪博客中提供的页面,把文字作为参数传过去就OK了。

代码如下:

.tooltip

{

width:120px;

height:23px;

line-height:23px;

background-color:#CCCCCC;

}

.tooltip a

{

color: #333333;

display: block;

font-size: 12px;

font-weight: bold;

text-indent: 10px;

}

$(function () {

$("#blogContent").mouseup(function (e) {

var x = 10;

var y = 10;

var r = "";

if (document.selection) {

r = document.selection.createRange().text;

}

else if (window.getSelection()) {

r = window.getSelection();

}

if (r!= "") {

var bowen = "发送到新浪微博";

var tooltip = "

" + bowen + "
";

$("body").append(tooltip);

$("#tooltip").css({

"top": (e.pageY + y) + "px",

"left": (e.pageX + x) + "px",

"position": "absolute"

}).show("fast");

}

}).mousedown(function () {

$("#tooltip").remove();

});

})

function ask(r) {

if (r != "") {

window.open('http://v.t.sina.com.cn/share/share.php?searchPic=false&title='+r+'&url=http://www.nowwamagic.net&sourceUrl=http%3A%2F%2Fblog.sina.com.cn&content=utf-8&appkey=1617465124', '_blank', 'height=515, width=598, toolbar=no, menubar=no, scrollbars=auto, resizable=yes, location=no, status=yes');

}

}

words words words words words words words words words。

就这么简单哦,大家可以自己试试哈。当然获得选中文本还可以有其他操作,这儿只是取巧调用了新浪的页面,大家如果有兴趣可以自己创建应用自己实现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值