标签:
分享到新浪账号
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>分享到新浪账号</title> <style> .img_sina_share{display:none; position:absolute; cursor:pointer;} </style> </head> <body> <div> <h1>页面选中文字分享到新浪微博</h1> <div id="body" class="light"> <div id="content" class="show"> <div class="demo"> <div id="testContent" class="f14"> <p> 鼠标划过去可以把你所选中的文字分享到自己的新浪微博账号</p> </div> <img id="imgSinaShare" class="img_sina_share" title="将选中内容分享到新浪微博" src="http://simg.sinajs.cn/blog7style/images/common/share.gif" /> </div> </div> </div> </div> <script> var eleImgShare = document.getElementById("imgSinaShare"); var $sinaMiniBlogShare = function(eleShare, eleContainer) { 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;//新浪logo浮出的位置 if (txt) { eleShare.style.display = "inline"; eleShare.style.left = left + "px"; eleShare.style.top = top + "px"; } else { eleShare.style.display = "none"; } }; eleShare.onclick = function() { 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); } }; }(eleImgShare); </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/mymission/p/5670065.html