GM.deleteValue: Difference between revisions
m added descriptions to code examples; |
Added extra example |
||
Line 33: | Line 33: | ||
var keys = GM_listValues(); | var keys = GM_listValues(); | ||
for (var i=0, key=null; key=keys[i]; i++) { | for (var i=0, key=null; key=keys[i]; i++) { | ||
GM_deleteValue(key); | |||
} | |||
</pre> | |||
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion: | |||
<pre class='sample'> | |||
var keysToKeep = ['a','foo','bar']; | |||
var keys = GM_listValues(); | |||
for (var i=0, key=null; key=keys[i]; i++) { | |||
if(keysToKeep.indexOf(key) >= 0) { | |||
continue; | |||
} | |||
GM_deleteValue(key); | GM_deleteValue(key); | ||
} | } |
Revision as of 00:43, 11 May 2011
Description
This method deletes an existing name / value pair from storage.
See GM_setValue for details regarding the storage of these values.
Syntax
function GM_deleteValue( name )
Compatibility: Greasemonkey 0.8.1+
Arguments
name
- Property name to delete. See GM_setValue for details on what names are valid.
Returns
undefined
Examples
Delete the stored name / value pair that has the name 'foo':
GM_deleteValue("foo");
Example showing the use of GM_listValues to delete all stored name / value pairs:
var keys = GM_listValues(); for (var i=0, key=null; key=keys[i]; i++) { GM_deleteValue(key); }
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:
var keysToKeep = ['a','foo','bar']; var keys = GM_listValues(); for (var i=0, key=null; key=keys[i]; i++) { if(keysToKeep.indexOf(key) >= 0) { continue; } GM_deleteValue(key); }
See Also
Notes
An issue that some may encounter on some platforms is that the values appear to not be deleted or set. This is usually due to a refreshing issue in the browser. If about:config is refreshed in the window/tab this should resolve any questions about stability of setting and deleting system preferences.