From 7ed2eda35ca100354c73a47b5e62a9dc8fc375c3 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 21 Sep 2023 14:13:49 +0100 Subject: [PATCH] Prevent browser from refilling input on tab reopen Only consistent way is to use JS to create textarea --- www/static/js/site.js | 23 ++++++++++++++++++++--- www/templates/get.gohtml | 1 - www/templates/set.gohtml | 2 -- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/www/static/js/site.js b/www/static/js/site.js index a2313a8..5d5447e 100644 --- a/www/static/js/site.js +++ b/www/static/js/site.js @@ -1,6 +1,13 @@ window.onload = function () { let naclfac = nacl_factory.instantiate(decrypt) + let txtArea = document.createElement('textarea') + txtArea.setAttribute( "id","data") + txtArea.setAttribute( "class","form-control") + txtArea.setAttribute( "rows", "15") + txtArea.setAttribute("placeholder","your message...") + document.getElementById('inputs').insertBefore(txtArea, document.getElementById('inputs').firstChild) + const onSubmit = async (e) => { e.preventDefault() let nacl = await naclfac @@ -96,8 +103,18 @@ function getURL() { return document.getElementById('accessUrl').innerHTML } -} -window.onbeforeunload = function() { - document.getElementById('data').value = "" + window.onbeforeunload = function () { + data.value = "" + } + + window.onunload = function () { + data.value = "" + } + + window.onpagehide = function () { + data.value = "" + } } + + diff --git a/www/templates/get.gohtml b/www/templates/get.gohtml index d597a42..8a0e5f4 100644 --- a/www/templates/get.gohtml +++ b/www/templates/get.gohtml @@ -2,7 +2,6 @@

- diff --git a/www/templates/set.gohtml b/www/templates/set.gohtml index 1c7c7b7..5b3dcbd 100644 --- a/www/templates/set.gohtml +++ b/www/templates/set.gohtml @@ -1,7 +1,5 @@ {{ define "content" }}
- -