JSFiddle - React, Tailwind, and code Playground
HTML
You should be able to type in these and "backspace" should work.<br/><input/><input readonly="readonly" value="test"/><br/>
But it shouldn't work to trigger the back button anywhere.
JavaScript
document.onkeydown = function (event) {
var doPrevent = false;
var keyCode = event.charCode ? event.charCode : event.keyCode;
if(keyCode !== 8){
return;
}
var d = event.srcElement || event.target;
if ((d.tagName.toUpperCase()==='INPUT' &&
(d.type.toUpperCase()==='TEXT' || d.type.toUpperCase()==='PASSWORD'))
|| d.tagName.toUpperCase() === 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
}
else {
doPrevent = true;
}
if (doPrevent) {
event.preventDefault();
}
};