轉自: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.");