2016-11-04 70 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%;">