jQuery實現滑鼠選文字發新浪微博的方法,jquery新浪

來源:互聯網
上載者:User

jQuery實現滑鼠選文字發新浪微博的方法,jquery新浪

本文執行個體講述了jQuery實現滑鼠選文字發新浪微博的方法。分享給大家供大家參考,具體如下:

最近注意到新浪部落格有個小功能,就是當滑鼠選中一段文字時會浮現一個小圖片,點擊這個圖片可以把選中內容發送到新浪微博,一時興起昨晚就寫了一個Demo玩了一下,代碼超簡單,沒最佳化,有興趣的朋友可以自己改進。

原理很簡單,先獲得滑鼠選中文字,然後調用新浪部落格中提供的頁面,把文字作為參數傳過去就OK了。

代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">  <title></title>  <style type="text/css">    .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;    }  </style>  <script src="jquery.min.js"></script>  <script type="text/javascript">    $(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 = "<div id='tooltip' class='tooltip'><a onclick=ask('"+r+"')>" + bowen + "</a></div>";          $("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');      }    }  </script></head><body>  <div id="blogContent">    words words words words words words words words words。  </div></body></html>

就這麼簡單哦,大家可以自己試試哈。當然獲得選中文本還可以有其他動作,這兒只是取巧調用了新浪的頁面,大家如果有興趣可以自己建立應用自己實現。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.