我有一个 Twitter 插件,可以打印 t.co 链接。我怎样才能用 jQuery 'un-short' 它们?有我可以使用的库吗?
我做了一些搜索,但找不到任何东西。也许我正在寻找错误的东西......
最佳答案
我在这里做了一个 fiddle :http://jsfiddle.net/duotrigesimal/XB8Uf/
它向 LongURL ( http://longurl.org/api#expand-url ) 的 api 发出请求以获取扩展的 url。
var tests = [
'http://t.co/NJwI2ugt',
'http://www.google.com' //nothing should happen
];
var expander = {
expand: function (url, callback) {
$.ajax({
dataType: 'jsonp',
url: 'http://api.longurl.org/v2/expand',
data: {
url: url,
format: 'json'
},
success: function(response) {
callback(response);
}
});
}
};
for(i in tests) {
expander.expand( tests[i], function(response) {
$('#output').append(response['long-url']+'<br>');
console.dir(response);
});
}
关于javascript - 如何使用 jQuery 取消缩短 t.co 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14759874/