分享

选中后分享到微博的js代码

 四两哥 2012-08-28
<!-- 选中后分享到微博 -->
<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="将选中内容分享到新浪微博" src="http://www./sj/images/share.gif" />
<img id="imgQqShare" class="img_qq_share" title="将选中内容分享到腾讯微博" 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 : "未命名页面";
        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 : "未命名页面";
        if (txt) {
            window.open( 'http://v.t.qq.com/share/share.php?title=' + txt + '&url=' + window.location.href);    
        }
    };
}(eleImgShare,eleImgShare2,artMain);

</script>
<!-- 选中后分享到微博 end -->

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多