skip to Main Content

enter image description here

How can I prevent any user from opening disabled input in the browser? Is there an easy way to do this or what should I do?

I use Vuejs in my project

I need to do this as a security measure
I couldn’t find a solution

2

Answers


  1. If you mean that the user cannot type on the input field, there are many ways and strategies you can do it and this can be tricky. Some of which that I can think of are as follows.

    • Create a fake input field (For instance, a <div> styled to make it look like an <input> and the real <input> is on display: none; and display it whenever you want the <input> to be accessed.
    • Add event listeners – one example is the click event and the blur() function:

    Code for option 2:

    <body>
        <input type="text" name="test" onfocus="preventFocus(event)"/>
    </body>
    <script>
    function preventFocus(event) {
        event.target.blur();
    }
    </script>
    

    The onfocus attribute of <input> fires when the user is about to type to the field while the blur() function removes the focus.

    Login or Signup to reply.
  2. If you mean that you don’t want users to open devtool and inspect your input tag and remove disable property, it is impossible.

    But security concerns can be satified by other methods such as validating it from submit event or through backend APIs.

    Therefore you should approach it in other way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search