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: | ||
== 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: [[Version_history#4.0_2|Greasemonkey 4.0+]] | |||
= | === Arguments === | ||
; <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. | |||
= | === Returns === | ||
A [[Promise]], resolved successfully with no value on success, rejected with no value on failure. | |||
== Examples == | |||
[[Category: | 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
orBoolean
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");