最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does calling indexedDB.deleteDatabase prevent me from making any further transactions? - Stack Overflow

programmeradmin4浏览0评论

If I go into my browser's console (I'm using Chrome) right now, on this very page, and type

indexedDB.open("MyDB").onsuccess = function(e) { console.log("success"); };

I immediately get a "success" message in my console. I can do this as many times as I like, and it works fine. But then if I type

indexedDB.deleteDatabase("MyDB").onsuccess = function(e) { console.log("success"); };

I get no "success" message back. Not only that, but if I then try and call .open again, I also get no "success" message back. How can I cure this strange illness caused by .deleteDatabase, and what exactly is happening?

(PS: Just as I finished typing this answer, I think the "success" message from the call to .deleteDatabase finally did e through, about two minutes after I made the call - but the question stands).

If I go into my browser's console (I'm using Chrome) right now, on this very page, and type

indexedDB.open("MyDB").onsuccess = function(e) { console.log("success"); };

I immediately get a "success" message in my console. I can do this as many times as I like, and it works fine. But then if I type

indexedDB.deleteDatabase("MyDB").onsuccess = function(e) { console.log("success"); };

I get no "success" message back. Not only that, but if I then try and call .open again, I also get no "success" message back. How can I cure this strange illness caused by .deleteDatabase, and what exactly is happening?

(PS: Just as I finished typing this answer, I think the "success" message from the call to .deleteDatabase finally did e through, about two minutes after I made the call - but the question stands).

Share Improve this question asked Feb 1, 2016 at 17:59 Jack MJack M 6,0157 gold badges52 silver badges77 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 16

Every time you call indexedDB.open a new connection to the database is established. When you call deleteDatabase all those open connections will get versionchange events. They can each listen for that event and close their connections in response. That is your first option. If they do not, the request returned by indexedDB.deleteDatabase("whatever") will receive a blocked event. This is what is happening in your case. Your second option is to listen to the blocked event and close the connections there:

var request = indexedDB.deleteDatabase("MyDB");
request.onsuccess = function(e) { console.log("success"); };
request.onblocked = function(e) {
  console.log("blocked: " + e);
  // Close connections here
};
request.onerror = function(e) { console.log("error: " + e); };

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论