Google Gear 基本使用方法

转自:http://zybingliu.blogspot.com/2009/04/google-gear.html

Google Gear从例子上看,好像很容易使用(当然,仅仅是最基本的入门):


首先通过例子的gears_init.js生成一个Google Gears对象:google.gears
后面所有的操作通过这个对象进行。这个就直接抄gears_init.js实现,自己不用做任何处理了。

对google.gears对象的判断:
if (!window.google || !google.gears) {
    textOut("NOTE:  You must install Gears first."); --- 提示没有安装google gear,
  } else { ---- 安装了google gear,生成自己的localserver和store
    localServer = google.gears.factory.create("beta.localserver");
    store = localServer.createManagedStore(STORE_NAME);
    textOut("Yeay, Gears is already installed.");
  }

其中的:STORE_NAME就是一个自己随意取的名字;

MANIFEST的文件,在create store的时候使用到
  if (!window.google || !google.gears) { --- 判断是否安装了gear
    alert("You must install Gears first.");
    return;
  }

  store.manifestUrl = MANIFEST_FILENAME; --- 这个就是定义manifest文件名字的,而且mainfest的文件,要和当前的页面放在同一个目录中(如果没有设置目录的话)
  store.checkForUpdate();                                       --- 对store的创建更新

  var timerId = window.setInterval(function() {  --- 这是一个把更新的状态显示出来的脚本
    // When the currentVersion property has a value, all of the resources
    // listed in the manifest file for that version are captured. There is
    // an open bug to surface this state change as an event.
    if (store.currentVersion) {
      window.clearInterval(timerId);
      textOut("The documents are now available offline./n" + 
              "With your browser offline, load the document at " +
              "its normal online URL to see the locally stored " +
       "version. The version stored is: " + 
              store.currentVersion);
    } else if (store.updateStatus == 3) {
      textOut("Error: " + store.lastErrorMessage);
    }
  }, 500);  


删除一个store也是相当容易的:
  if (!window.google || !google.gears) {
    alert("You must install Gears first.");
    return;
  }

  localServer.removeManagedStore(STORE_NAME); --- 删除,这个STORE_NAME就是上面创建时候的STORE NAME
  textOut("Done. The local store has been removed." +
          "You will now see online versions of the documents.");

原文链接: http://blog.csdn.net/vanessa219/article/details/4441289

转载于:https://my.oschina.net/chen106106/blog/44410

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值