/  Technology   /  How to disable Chrome find text from Matching Text on a “Position:fixed” element in Javascript?
js

How to disable Chrome find text from Matching Text on a “Position:fixed” element in Javascript?

 

We can disable chrome find text from Matching Text on a “Position:fixed” element by following the below code.

Here we have created a keyboard event listener function, named addEventListener

The Window keyword represents a window containing a DOM document.

Window is a global variable created, representing the window in which the script is running or is exposed to JavaScript code.

In the addEventListener function, we are passing a parameter that is “keydown” and inside the function, we passed an if condition which is an if event. keycode is equal to 114 or on pressing the control key and event. keycode is true and equal to 70, then passing event.preventDefault method that cancels the event if it is cancellable, meaning that the default action that belongs to the event will not occur. Hence by passing this function in the script we can disable chrome find text from Matching Text on a “Position:fixed” element

window.addEventListener("keydown", (e) => {
  if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
    e.preventDefault();
  }
})

 

 

Leave a comment