DeleteFile in Local Storage

Share your advanced knowledge/code with the community.
ljgww
Posts: 26
Joined: Thu Mar 26, 2020 5:47 pm

DeleteFile in Local Storage

Post by ljgww »

I did not find a command to delete 'file' from the LocalStorage in the list of File functions in SB.
I needed this, so I made a little workaround (by not doing anything but interfacing it). Here it is:

Code: Select all

Procedure DeleteFileLocalStorage(Filename.s)
Debug "* DeleteFile: " + Filename
EnableJS
LocalForage.removeItem('sbfs_'+v_filename).then(function() {
    // Run this code once the key has been removed.
    console.log('Key is cleared!');
  }).catch(function(err) {
    // This code runs If there were any errors
    console.log(err);
    });
DisableJS
EndProcedure
Source: https://localforage.github.io/localFora ... removeitem

Of course: if you do this, to be able to see the effect of deleting, you need to refresh the browser window.
loulou2522
Posts: 48
Joined: Wed Mar 18, 2015 5:52 am

Re: DeleteFile in Local Storage

Post by loulou2522 »

I try this function but it doesn't work ?
Can someone know while

Code: Select all

Procedure DeleteFileLocalStorage(Filename.s)
Debug "* DeleteFile: " + Filename
EnableJS
LocalForage.removeItem('sbfs_'+v_filename).then(function() {
    // Run this code once the key has been removed.
    console.log('Key is cleared!');
  }).catch(function(err) {
    // This code runs If there were any errors
    console.log(err);
    });
DisableJS
EndProcedure

DeleteFileLocalStorage("Preferences.prefs")
User avatar
Peter
Posts: 937
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: DeleteFile in Local Storage

Post by Peter »

loulou2522 wrote: Fri Sep 03, 2021 8:17 amI try this function but it doesn't work ?
Are you getting an error? If so, what is it?
loulou2522
Posts: 48
Joined: Wed Mar 18, 2015 5:52 am

Re: DeleteFile in Local Storage

Post by loulou2522 »

There is no error . The file that i want to delete come from preference.sbi
Here is the debugging
references.prefsGlobalVersion: 1.1b
Preferences.prefsWindowWindowX: 123
sb_test1: testing 1
Preferences.prefsWindow:
Preferences.prefsWindowWindowY: 124
sb_test2: testing 2
Preferences.prefsGlobalApplicationName: MP3 Player
Preferences.prefsWindowWindowZ: -125.5
sb_test3: testing 3
Preferences.prefsGlobal:
obtain by the following programm

Code: Select all

Procedure DeleteFileLocalStorage(Filename.s)
  Debug "* DeleteFile: " + Filename
 
  EnableJS
  ;   
 spider.debug.Print(s1+v_filename);

LocalForage.removeItem('sbfs_'+v_filename).then(function() {
// Run this code once the key has been removed.
    console.log('Key is cleared!');
  }).catch(function(err) {
    // This code runs If there were any errors
    console.log(err);
    })  ;
    alert(err) ;
 DisableJS
EndProcedure
DeleteFileLocalStorage("preference1.pref")
Javscript Error Message
Uncaught ReferenceError: s1 is not defined
at f_deletefilelocalstorage (spiderbasic.js:272)
at SpiderLaunch (spiderbasic.js:287)
at SpiderMain (main.js:24)
at main.js:41
at fa (dojo.js:19)
at dojo.js:20
at ga (dojo.js:20)
at da (dojo.js:20)
at s (dojo.js:22)
at HTMLScriptElement.<anonymous> (dojo.js:27)
Post Reply