GM.setValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(replace _ with .)
 
(49 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
== Description ==
{{underscore|title=GM_setValue}}


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


'''GM_setValue(''' ''name'', ''value'' ''')'''
Strings, booleans, and integers are currently the only allowed data types.


= Description =
== Syntax ==


Allows user script authors to persist simple values locally.
{{Function|GM.setValue|name, value}}
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.
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]
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 =
=== Arguments ===


alert(GM_setValue("foo", "bar"));
; <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.


= See Also =
=== Returns ===


* [[GM_getValue]]
A [[Promise]], resolved successfully with no value on success, rejected with no value on failure.


== Examples ==


[[Category:API Reference|S]]
Set the name foo to hold the value bar:
 
<pre class='sample'>
GM.setValue("foo", "bar");
</pre>
 
== See Also ==
 
* [[GM.getValue]]
* [[GM.deleteValue]]
* [[GM.listValues]]
 
[[Category:API_Reference|S]]

Latest revision as of 00:26, 19 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