2012-02-22 145 views
2

我在Firefox和Chrome中使用HTML5規範中的IndexedDB API。未在Chrome中觸發IndexedDB onversionchange事件

有些東西不能按預期工作我想在這裏分享它,因爲我不知道它是我的錯還是瀏覽器錯誤。

按照API,有一個名爲onversionchange當您打開到本地數據庫的連接和使用的版本號低於數據庫一個更大的多數民衆贊成觸發的事件。 我的問題是,這個事件是在Firefox中觸發的,而不是在Chrome中觸發的。

一些示例代碼嘗試幾種模式:

var db; 
var DB_VERSION = 5; 
var openRequest = iDb.open("test_db", DB_VERSION, function() { 
    console.log("This is the place where I can change db structure"); 
}); 
openRequest.onSuccess = function(event) { 
    db = openRequest.result; 
}; 
openRequest.onversionchange = function(event) { 
    console.log("This is the place where I can change db structure"); 
}; 
openRequest.onupgradeneeded = function(event) { 
    console.log("This is the place where I can change db structure"); 
}; 

onversionchage事件,當我更改版本號沒有被甚至被解僱。

UPDATE 作爲ebidel已經回答了,Chrome瀏覽器實現The並不遵循當前規範,這樣,纔能有一個跨broswser客戶端代碼,我們需要處理兩種情況:onversionchange事件和數據庫。版本手動比較。

這裏有一對夫婦的代碼示例鏈接: Chromium google groupHTML5 Rocks!

回答

3

Chrome的IndexedDB的實現是基於關閉舊版本,它使用舊setVersion調用,而不是onversionchange/onupgradeneeded規範的。請爲此問題明星:http://crbug.com/108223