在用户登录之前,阻止通过浏览器创建HTML5 ApplicationCache

时间:2014-02-18 09:36:49

标签: html5 caching sinatra html5-appcache offline-caching

我的应用程序旨在与HTML5 appcache脱机工作。有没有办法我可以禁用下载appcache,直到用户通过登录界面进行身份验证?这样,仅当有效用户访问页面并阻止将应用程序缓存到其他用户使用的设备时,才会创建appcache。这是可能的,如果可以,怎么样?

P.S。我尝试了以下方法:

$window.applicationCache.addEventListener('checking', function(event){
  event.preventDefault();
  // or
  event.abort();
}, false);

// and the following way

window.addEventListener('load', function(event) {
  window.applicationCache.addEventListener('checking', function(e) {
    window.applicationCache.abort();
      e.preventDefault();
  }, false);
}, false);

// and even this

window.applicationCache.addEventListener('downloading', function(e) {
    window.applicationCache.abort();
    e.preventDefault();
}, false);

上述任何内容似乎都不起作用,浏览器在运行时仍然会有appcache。

1 个答案:

答案 0 :(得分:1)

我没有对此进行过测试,但我相信您可以使用iframe填充应用程序缓存。查看此页面的来源以查看此操作的示例。

http://appcache-demo.s3-website-us-east-1.amazonaws.com/offline-iframe/

因此,对于您的方案,只有在登录完成后,您才能以编程方式附加带有指向清单的链接的iframe。然后,您可以将登录页面作为该清单的一部分包含在内,以便成功登录的用户以后的访问即使在离线状态下也能正常工作。