Skip to content

Commit

Permalink
Prevent browser from refilling input on tab reopen
Browse files Browse the repository at this point in the history
Only consistent way is to use JS to create textarea
  • Loading branch information
vsliouniaev committed Sep 21, 2023
1 parent b9e44cc commit 7ed2eda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
23 changes: 20 additions & 3 deletions www/static/js/site.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = ""
}
}


1 change: 0 additions & 1 deletion www/templates/get.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<input id="encrypted" type="hidden" value="{{ . }}"/>
<div id="inputs">
<br/>
<textarea id="data" class="form-control" rows="15"></textarea>
<div class="centered">
<a href="/">Return</a>
</div>
Expand Down
2 changes: 0 additions & 2 deletions www/templates/set.gohtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{{ define "content" }}
<div id="inputs">
<textarea id="data" class="form-control" rows="15" placeholder="your message..."></textarea>

<form id="form">
<br>
<div class="float-end">
Expand Down

0 comments on commit 7ed2eda

Please sign in to comment.