相关疑难解决方法(0)

使用image.complete来查找图像是否缓存在chrome上?

我一直试图找出一个外部图像是否在js上缓存在浏览器上,这是我到目前为止的代码:

<html>
    <head></head>
    <body>

    <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

    <script>

        function cached( url ) {
            $("#imgx").attr({"src":url});
            if(document.getElementById("imgx").complete) {
                return true;
            } else {
                if( document.getElementById("imgx").width > 0 ) return true;
            }

            return false;
        }

    </script>

    <img id="imgx" src=""  />

    <script>

        $(document).ready(function(){
            alert(cached("http://www.google.com/images/srpr/nav_logo80.png"));
        });

    </script>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

它在firefox上完美运行,但它总是在chrome上返回false.

有人知道如何使用chrome吗?

javascript jquery image cross-browser image-caching

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

cross-browser ×1

image ×1

image-caching ×1

javascript ×1

jquery ×1