分享推文不起作用

时间:2018-02-19 19:40:52

标签: javascript

我为挑战构建了一个随机引用机器,其中一个要求是包含我做的推文按钮。 唯一的问题是推文按钮在我的本地机器上工作,我能够在Google Chrome 中发推文,如果我使用Firefox开发人员版或Codepen,推文按钮甚至不起作用如果代码完全相同。

https://codepen.io/HacNass/full/QQMRNR/

$(document).ready(function () {
$("#newQuote").on("click", function() {
    $.getJSON("http://quotes.stormconsultancy.co.uk/popular.json", function(json) {

        // getting a random number to pick a json object randomly
        var jsonLength = json.length;
        var randomQuoteNumber;
        function getRandomInt(randomInt) {
            return Math.floor(Math.random() * Math.floor(randomInt));
        };

        randomQuoteNumber = getRandomInt(jsonLength);
        console.log(randomQuoteNumber);

        // Store the random quote machine composnents in respective variables   
        var randomQuote = json[randomQuoteNumber].quote;
        var randomAuthor = json[randomQuoteNumber].author;

        // update the html elements with a random quote and author from the json API
        $("#quoteHolder").html(randomQuote);
        $("#author").html(randomAuthor);

        $("#tweetButton").on("click", function() {
            $("a").attr("href", "https://twitter.com/intent/tweet?hashtags=randomQuoteMachine&text="
                                                    + encodeURIComponent(randomQuote + " - " + randomAuthor));
        });


    });
});

});

提前感谢您的帮助!

0 个答案:

没有答案