隐藏关注按钮Twitter Card Blockquote

时间:2014-06-20 19:47:26

标签: button twitter hide

我需要使用以下方法隐藏Twitter卡上的关注按钮:

<blockquote width="581" height="250" class="twitter-tweet"><p></p><a href="https://twitter.com/twitterapi/status/'+tt[i][1]+'" data-datetime="2011-11-07T20:21:07+00:00"></a></blockquote></div>

如何隐藏卡片上的关注按钮?

由于

1 个答案:

答案 0 :(得分:0)

twitter小部件扩展为iframe,因此您必须等到它完全加载。然后你可以完全删除按钮或隐藏它。你需要一点JavaScript。问题是你必须等到它被加载。我不知道如何在推文完全加载时抓住,所以我会每隔100毫秒检查按钮,直到它出现。您当然可以根据自己的需要进行更改。

JS:

window.setTimeout(removeButton, 100);

function removeButton() {
    var iframe = document.querySelector('iframe.twitter-tweet');
    if(iframe == undefined) {
        window.setTimeout(removeButton, 100);
        return;
    }
    var button = iframe.contentDocument.querySelector('.follow-button.profile');
    if(button == undefined) {
        window.setTimeout(removeButton, 100);
        return;
    }

    //Hide
    button.style.display = 'none';

    //Or remove
    button.parentNode.removeChild(button); //Note: Not using button.remove() because of compatibility
}

这当然现在只适用于一条推文。如果你想删除多个Follow按钮,你必须稍微修改一下这个脚本。

相关问题