GM.deleteValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Kwah (talk | contribs)
Added extra example
m Arantius moved page GM deleteValue to GM.deleteValue: Greasemonkey 4.0
(No difference)

Revision as of 14:15, 3 November 2017


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.