A
A
Arthur Belan2020-06-20 23:14:14
JavaScript
Arthur Belan, 2020-06-20 23:14:14

How to inpu save the contents of this field in the state history. History API?

How to save the contents of this field in the state history with each change in the content of the input field.

userText.addEventListener("input", () => {
    document.getElementById("char-count").innerHTML = userText.value.length;
    saveState(userText);
});

function saveState(object) {
    history.pushState({ saved: object }, "Additional information");
}

console.log(history);

Why does not it work?
This example works, but the question is how to write the content?
history.pushState({foo: 'bar'}, 'Title', '/baz.html')

Should I use JSON in foo ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Belan, 2020-06-21
@Belartale

I decided!
Only it is necessary that not by the piece, but the entire field is recorded

userText.addEventListener("input", () => {
    document.getElementById("char-count").innerHTML = userText.value.length;
    saveState(userText.value);
});

function saveState(object) {
    let objectJson = JSON.stringify(object);
    history.pushState({ page: objectJson }, "title", "?page");
    console.log(history);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question