Difference between revisions of "GM.setValue"

From GreaseSpot Wiki
Jump to navigationJump to search
(about:config)
(replace _ with .)
 
(48 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
== Description ==
{{underscore|title=GM_setValue}}
 
This method allows user script authors to persist simple values across page loads and across origins.
 
Strings, booleans, and integers are currently the only allowed data types.


== Syntax ==
== Syntax ==


'''GM_setValue(''' ''name'', ''value'' ''')'''
{{Function|GM.setValue|name, value}}
 
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]
 
=== Arguments ===


= Description =
; <code>name</code>
: <code>String</code> The unique (within this script) name for this value.  Should be restricted to valid Javascript identifier characters.
; <code>value</code>
: <code>String</code>, <code>Integer</code> or <code>Boolean</code>  Any valid value of these types.  Any other type may cause undefined behavior, including crashes.


Allows user script authors to persist simple values locally.
=== Returns ===
Strings, booleans, and integers are the only allowed data types.


Values are stored in the [http://developer.mozilla.org/en/docs/Code_snippets:Preferences Firefox preferences] back end and can be changed by typing <code>about:config</code> in the address bar and searching for the preference name "greasemonkey.scriptval.''script-namespace''/''script-name''.
A [[Promise]], resolved successfully with no value on success, rejected with no value on failure.
This places limitations on the size of an individual value, and the number of values.
(This statement may not be accurate.  Please see [http://groups.google.com/group/greasemonkey-users/t/ca5a0dfac5c5998b this mailing list thread] for details.)


== Examples ==
== Examples ==


alert(GM_setValue("foo", "bar"));
Set the name foo to hold the value bar:


== See also ==
<pre class='sample'>
GM.setValue("foo", "bar");
</pre>


* [[GM_getValue]]
== See Also ==


* [[GM.getValue]]
* [[GM.deleteValue]]
* [[GM.listValues]]


[[Category:API Reference|S]]
[[Category:API_Reference|S]]

Latest revision as of 19:26, 18 September 2018

Description

This method allows user script authors to persist simple values across page loads and across origins.

Strings, booleans, and integers are currently the only allowed data types.

Syntax

function GM.setValue( name, value )

Compatibility: Greasemonkey 4.0+

Arguments

name
String The unique (within this script) name for this value. Should be restricted to valid Javascript identifier characters.
value
String, Integer or Boolean Any valid value of these types. Any other type may cause undefined behavior, including crashes.

Returns

A Promise, resolved successfully with no value on success, rejected with no value on failure.

Examples

Set the name foo to hold the value bar:

GM.setValue("foo", "bar");

See Also