0

I want to create an weabpp with a button. By clicking on the button, I want to store a string in the JavaScript IndexedDB. I need a function. Writing it in the onupgradneeded event, could'nt help me. My acctual code is this:

<script>    
function createDB(dbName, dbVersion) {
    const request = indexedDB.open(dbName, dbVersion)

    // upgrade needed
    request.onupgradeneeded = e => {
        const db = e.target.result
        db.createObjectStore("wdesk")
        console.log("Upgrade is called")
    }

    // successful
    request.onsuccess = e => {
        console.log("Success")
    }

    // error
    request.onerror = e => {
        console.log("Error")
    }
}
<script>
<button onclick="">Store HelloWorld</button>

1 Answers1

0

I think if you have just one field you can store data in local storage

sajadab
  • 383
  • 2
  • 11
  • I have lot of fields. I create an full local registration and file system in the application. At the moment I still use localStorage, but it has max. 5.9MB. –  Jul 16 '22 at 22:19
  • If you have lots of fields you can use indexed db. The best library for this case is https://dexie.org/ – sajadab Jul 17 '22 at 12:11