javascript - 如何使用 jQuery 取消缩短 t.co 链接?

标签 javascript jquery html twitter

我有一个 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/

相关文章:

javascript - 自动完成标签不显示隐藏元素上的数据

javascript - 以小时和分钟为单位的范围 slider javascript

javascript - JS 验证高亮输入字段红色/绿色

javascript - 缓冲代码和非缓冲代码有什么区别?

javascript - 将 CSS 样式规则转换为 HTML 元素(反之亦然)

javascript - Ant Design Popconfirm - 将预选按钮更改为取消

jquery - 如何使用 jQuery 获得脉动效果?

javascript - 更改网站中按钮的功能

javascript - React-query 不适用于使用 Vite 引导的项目

javascript - DIV 获取不到鼠标事件