2016-11-04 66 views

回答

1

我有2個有用的資源,爲您提供:

這一個谷歌網址縮短服務:http://www.i-visionblog.com/2014/07/google-url-shortener-api-javascript.html

這一個bit.ly的:https://bdhacker.wordpress.com/2010/03/30/dynamically-use-bitly-in-your-site-easiest-way/

首先,你需要一個帳戶http://bit.ly。要創建一個,請轉至 網站並註冊。

一旦你註冊,登錄並進入你的賬戶頁面。在那裏,你 會找到你的API密鑰。

在HTML HEAD將這個:

<script type="text/javascript" charset="utf-8" src="http://bit . ly/javascript-api.js?version=latest&login=******&apiKey=*****************"></script> 

(刪除空格在bit.ly網址計算器不允許張貼有該網址的答案。)


將這個</body>

<script> 
    // Bit.ly API 
    BitlyCB.shortenResponse = function(data) { 
      var sss = ''; 
      var first_result; 
      // Results are keyed by longUrl, so we need to grab the first one. 
      for  (var r in data.results) { 
        first_result = data.results[r]; break; 
      } 
      sss = first_result["shortUrl"].toString(); 
      document.getElementById("qlink").value = sss; 
    } 
    BitlyClient.shorten(window.location, 'BitlyCB.shortenResponse'); 
</script> 

而這一點,在你的頁面的話:

<h3>Link to this page</h3><br> 
Use this link to tell others about this page! <input onclick = "this.select()" type = 'text' id = "qlink" style = "width:100%;">