Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
How can I catch the click outside the browser - Javascript

For my project, I need to catch all the click outside the browser in Javascript. Is there a way to do that ? For example by asking the user the right access ? I need a function like "onclick" that works even outside the browser.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

There are various approaches for detecting when the focus moves out of the current page which would be a side effect of clicking outside the window if the window currently has focus.

Explicitly detecting clicks outside the page is not possible. It would be a security problem if a web page could monitor how the user interacts with other applications.

about 4 years ago · Santiago Trujillo Report

0

To detect click outside element with JavaScript, we can use the element’s contains method.

For instance, we write

const specifiedElement = document.getElementById("a");

document.addEventListener("click", (event) => {
  const isClickInside = specifiedElement.contains(event.target);

  if (!isClickInside) {
    // ...
  }
});

to select the element we want to check with getElemebntById.

Then we add a click listener for the whole page with document.addEventListener.

In the callback, we call specifiedElement.contains with event.target to check if we clicked inside the a element.

If it’s false, then we clicked outside of it.

about 4 years ago · Santiago Trujillo Report

0

javascript detect click outside of element

var ignoreClickOnMeElement = document.getElementById('someElementID');

document.addEventListener('click', function(event) {
    var isClickInsideElement = ignoreClickOnMeElement.contains(event.target);
    if (!isClickInsideElement) {
        //Do something click is outside specified element
    }
});

click outside javascript

// Vanilla js
var ignoreMe = document.getElementById("ignoreMe");
window.addEventListener('mouseup', function(event){
    if (event.target != ignoreMe && event.target.parentNode != ignoreMe){
    // Place your output
    }
});

https://www.codegrepper.com/code-examples/javascript/javascript+detect+click+outside+of+element

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!