zoukankan      html  css  js  c++  java
  • 选中文字分享到自己的新浪微博

    分享到新浪账号

    <!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>
    

      

  • 相关阅读:
    零知识证明,中间人攻击,盲签名:原理和应用——三篇密码学科普文章
    json
    优化自己的编写出来的C#程序
    C++中不同的继承方式
    C语言程序编写涉及内存的问题
    面向Android的Tesseract工具
    常见Linux使用的十大问题
    Java语言链接数据库连接池配置的两种技巧
    配置数据库连接池的技巧
    PHP和Java在Web开发下相比较
  • 原文地址:https://www.cnblogs.com/mymission/p/5670065.html
Copyright © 2011-2022 走看看