html http://stackoverflow.com/questions/32615926/use-javascript-to-get-a-random-image-from-google-im

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html http://stackoverflow.com/questions/32615926/use-javascript-to-get-a-random-image-from-google-im相关的知识,希望对你有一定的参考价值。

<html>
<head>
    <title></title>
    <script src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    google.load('search', '1');
    google.setOnLoadCallback(OnLoad);
    var search;

    //i suggest instead of this to make keywords list so first to pick random keyword than to do search and pick random image
    var keyword = 'mountains';

    function OnLoad()
    {
        search = new google.search.ImageSearch();

        search.setSearchCompleteCallback(this, searchComplete, null);

        search.execute(keyword);
    }

    function searchComplete()
    {
        if (search.results && search.results.length > 0)
        {
            var rnd = Math.floor(Math.random() * search.results.length);

            //you will probably use jQuery and something like: $('body').css('background-image', "url('" + search.results[rnd]['url'] + "')");
            document.body.style.backgroundImage = "url('" + search.results[rnd]['url'] + "')";
        }
    }
    </script>
</head>
<body>

</body>
</html>
<html>

<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        var keyword = "mountains";

        $(document).ready(function () {

            $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", {
                    tags: keyword,
                    tagmode: "any",
                    format: "json"
                },
                function (data) {
                    var rnd = Math.floor(Math.random() * data.items.length);

                    var image_src = data.items[rnd]['media']['m'].replace("_m", "_b");

                    $('body').css('background-image', "url('" + image_src + "')");

                });

        });
    </script>
</head>

<body>
</body>

</html>

以上是关于html http://stackoverflow.com/questions/32615926/use-javascript-to-get-a-random-image-from-google-im的主要内容,如果未能解决你的问题,请参考以下文章

html 基于IP的城市动态文本替换(也可用于区域,国家,IP)。文档:http://stackoverflow.com/questions

html Bootstrap 3子菜单 - http://stackoverflow.com/questions/18023493/bootstrap-3-dropdown-sub-menu-mis

html 提交后禁用按钮http://stackoverflow.com/questions/13606573/disable-button-after-submit-with-jquery

html Bootstrap 3子菜单 - http://stackoverflow.com/questions/18023493/bootstrap-3-dropdown-sub-menu-mis

html Bootstrap 3子菜单 - http://stackoverflow.com/questions/18023493/bootstrap-3-dropdown-sub-menu-mis

csharp 来自http://stackoverflow.com/questions/286813/how-do-you-convert-html-to-plain-text