Используйте localStorage
с beforeunload
и unload
:
window.onbeforeunload = function() {
var text1 = document.getElementById("text1").value;
var text2 = document.getElementById("text2").value;
localStorage.setItem("match", JSON.stringify(text1 == text2));
};
window.onload = function() {
if (JSON.parse(localStorage.getItem("match"))) {
alert("Texts match!");
} else {
alert("Texts don't match!");
}
};