Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:27:43+00:00 2026-05-27T13:27:43+00:00

I’m creating a Chrome extension using user’s key event. But I want to alert

  • 0

I’m creating a Chrome extension using user’s key event.
But I want to alert to user if the element already has been bound to a keyboard event.

How do I detect if key event is already bound?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:27:43+00:00Added an answer on May 27, 2026 at 1:27 pm

    This is tricky. The reality is, you can bind to an HTMLElement’s event in quite a few different ways. I suppose the easiest way to bind (and check to see if something is bound) would be something like this:

    var ele = document.getElementById("yourDiv");
    if (ele.onkeydown) {
      alert("onkeydown event is already bound");
    }
    else {
      ele.onkeydown = yourEventHandler;
    }
    

    The problem is, as asked in the comment section to this post, there’s no real way to detect events added by addEventListener or attachEvent with programattic javascript if you don’t have the ability to change the prototype for the HTML elements before the events are bound. (So a userscript can’t really change the prototypes before events are bound, because it’s run after all the scripts on the page are). However, if it’s your own page, and you’re just wanting to monitor for these event changes. You can hack it into the prototype by doing something like this:

    // cache the original event handler
    HTMLAnchorElement.prototype.realAddEventListener = HTMLAnchorElement.prototype.addEventListener;
    
    // now override it so you can add in your custom functionality
    HTMLAnchorElement.prototype.addEventListener = function(a,b,c){
        this.realAddEventListener(a,b,c); 
        // do whatever you want to cache those listening functions, maybe shove them in an array
        // for the current object
        if (!this.listeners) {  
            this.listeners = new Array();
        }
        this.listeners.push({a : a, b : b , c : c});
    };
    
    // code here that adds an event handler
    document.getElementById("txtField").addEventListener("keydown", function() {
      console.log("key down pressed"); 
    });
    
    // find the event listeners that are bound
    var listeners = document.getElementById("pressed").listeners;
    

    Looking, I found this question here which also covers this exact issue, and some good answers in there go in to alot of depth: How to find event listeners on a DOM node when debugging or from the JavaScript code?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.