<!-- 選中后分享到微博 --> <style> .img_sina_share{display:none; position:absolute; cursor:pointer;} .img_qq_share{display:none; position:absolute; cursor:pointer;} </style> <img id="imgSinaShare" class="img_sina_share" title="將選中內(nèi)容分享到新浪微博" src="http://www./sj/images/share.gif" /> <img id="imgQqShare" class="img_qq_share" title="將選中內(nèi)容分享到騰訊微博" src="http://www./sj/images/weiboicon32.png" width="26" height="26" /> <script> var eleImgShare = document.getElementById("imgSinaShare"); var eleImgShare2 = document.getElementById("imgQqShare"); var artMain = document.getElementById("artMain"); var $miniBlogShare = function(eleShare,eleShare2,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; 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() { var txt = funGetSelectTxt(), title = (eleTitle && eleTitle.innerHTML)? eleTitle.innerHTML : "未命名頁(yè)面"; if (txt) { window.open('http://v.t.sina.com.cn/share/share.php?title=' + txt + '&url=' + window.location.href); } }; eleShare2.onclick = function() { var txt = funGetSelectTxt(), title = (eleTitle && eleTitle.innerHTML)? eleTitle.innerHTML : "未命名頁(yè)面"; if (txt) { window.open( 'http://v.t.qq.com/share/share.php?title=' + txt + '&url=' + window.location.href); } }; }(eleImgShare,eleImgShare2,artMain); </script> <!-- 選中后分享到微博 end --> |
|