应用场景:之前手机上收到的垃圾短信都是一大串的连接;现在收到的基本上都是很短的连接
* 大部分长连接转短连接都是采用新浪微博平台的开放接口;下方实际也是采用微博提供的接口
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>生成短链接</title>
</head>
<!-- <script src="jquery-2.1.1.min.js"></script> -->
<body>
<input type="text" name="" id="url">
<button id="get_short">生成</button>
<a id="myDiv">点我</a>
</body>
<script type="text/javascript">
// 绑定按钮事件
btn_getshort = document.getElementById('get_short');
btn_getshort.onclick = function (){
var source = '3271760578';
var url = document.getElementById('url').value;
var all = 'http://api.t.sina.com.cn/short_url/shorten.json?source=' + source
+'&url_long='+ url;
document.getElementById("myDiv").href = all;
}
</script>
</html>
微博长链转短链的文档