Use anchor as query string.
The lib use document.location.hash
to store information like query string. If you have a compound data the lib store it with a valueDelimiter
which by default is =
then we would have key=value
. You can also store simple data in this case the lib use only the key
. Is possible to store more than one data, that will be separated by delimiter
which by default is &
.
To insert you can pass 3 arguments are:
- String
key
- String
value
// Simple
AnchorData.insert('flag'); // Inserts #flag
// Compound
AnchorData.insert('compound', 'value'); // Insert #compound=value
Remove a data.
AnchorData.remove('flag'); // Removes #flag
AnchorData.remove('compound'); // Removes #compound=new_value
Get data value
// Simple
AnchorData.get('flag'); // Returns true
// Compound
AnchorData.get('compound'); // Returns 'new_value'
// Not set
AnchorData.get('notset'); // Returns false
The lib emits some events to improve usage.
dataUpdated
dataInserted
dataRemoved
window.addEventListener('dataUpdated', function(e) {
...
});