html 5 web app cache download complete javascript alert? - Stack Overflow

I'm creating a very basic offline web app using a cache.manifestBut I have just under 5mb of cache

I'm creating a very basic offline web app using a cache.manifest

But I have just under 5mb of cache downloading to do. And I am wondering if there is a way of having a popup alert that runs once when the cache download is plete?

Thanks


I found this debugger which helps me debug wether I have missed anything on the manifest, don't know whether this can help in anyway?

<script>

    var cacheStatusValues = [];
    cacheStatusValues[0] = 'uncached';
    cacheStatusValues[1] = 'idle';
    cacheStatusValues[2] = 'checking';
    cacheStatusValues[3] = 'downloading';
    cacheStatusValues[4] = 'updateready';
    cacheStatusValues[5] = 'obsolete';

    var cache = window.applicationCache;
    cache.addEventListener('cached', logEvent, false);
    cache.addEventListener('checking', logEvent, false);
    cache.addEventListener('downloading', logEvent, false);
    cache.addEventListener('error', logEvent, false);
    cache.addEventListener('noupdate', logEvent, false);
    cache.addEventListener('obsolete', logEvent, false);
    cache.addEventListener('progress', logEvent, false);
    cache.addEventListener('updateready', logEvent, false);

    function logEvent(e) {
        var online, status, type, message;
        online = (navigator.onLine) ? 'yes' : 'no';
        status = cacheStatusValues[cache.status];
        type = e.type;
        message = 'online: ' + online;
        message+= ', event: ' + type;
        message+= ', status: ' + status;
        if (type == 'error' && navigator.onLine) {
            message+= ' (prolly a syntax error in manifest)';
        }
        console.log(message);
    }

    window.applicationCache.addEventListener(
        'updateready', 
        function(){
            window.applicationCache.swapCache();
            console.log('swap cache has been called');
        }, 
        false
    );

    setInterval(function(){cache.update()}, 10000);

</script>

I'm creating a very basic offline web app using a cache.manifest

But I have just under 5mb of cache downloading to do. And I am wondering if there is a way of having a popup alert that runs once when the cache download is plete?

Thanks


I found this debugger which helps me debug wether I have missed anything on the manifest, don't know whether this can help in anyway?

<script>

    var cacheStatusValues = [];
    cacheStatusValues[0] = 'uncached';
    cacheStatusValues[1] = 'idle';
    cacheStatusValues[2] = 'checking';
    cacheStatusValues[3] = 'downloading';
    cacheStatusValues[4] = 'updateready';
    cacheStatusValues[5] = 'obsolete';

    var cache = window.applicationCache;
    cache.addEventListener('cached', logEvent, false);
    cache.addEventListener('checking', logEvent, false);
    cache.addEventListener('downloading', logEvent, false);
    cache.addEventListener('error', logEvent, false);
    cache.addEventListener('noupdate', logEvent, false);
    cache.addEventListener('obsolete', logEvent, false);
    cache.addEventListener('progress', logEvent, false);
    cache.addEventListener('updateready', logEvent, false);

    function logEvent(e) {
        var online, status, type, message;
        online = (navigator.onLine) ? 'yes' : 'no';
        status = cacheStatusValues[cache.status];
        type = e.type;
        message = 'online: ' + online;
        message+= ', event: ' + type;
        message+= ', status: ' + status;
        if (type == 'error' && navigator.onLine) {
            message+= ' (prolly a syntax error in manifest)';
        }
        console.log(message);
    }

    window.applicationCache.addEventListener(
        'updateready', 
        function(){
            window.applicationCache.swapCache();
            console.log('swap cache has been called');
        }, 
        false
    );

    setInterval(function(){cache.update()}, 10000);

</script>
Share Improve this question asked Aug 13, 2013 at 9:01 JoshcJoshc 3,86316 gold badges81 silver badges125 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

In order to check when the cache download is plete, you are probably looking for the Cached event. It can be checked similar to the one you have above.

window.applicationCache.addEventListener('cached', function() {
    // anything you need to do for success
    alert('I'm done!');
}, false );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745381834a4625264.html

相关推荐

  • html 5 web app cache download complete javascript alert? - Stack Overflow

    I'm creating a very basic offline web app using a cache.manifestBut I have just under 5mb of cache

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信