Page 1 of 1
DeleteFile in Local Storage
Posted: Tue Apr 14, 2020 7:24 pm
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.
Re: DeleteFile in Local Storage
Posted: Fri Sep 03, 2021 8:17 am
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")
Re: DeleteFile in Local Storage
Posted: Fri Sep 03, 2021 10:32 am
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?
Re: DeleteFile in Local Storage
Posted: Fri Sep 03, 2021 10:54 am
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)