can not preventDefault() on CTRL+D

RESOLVED INVALID

Status

RESOLVED INVALID
15 years ago
14 years ago

People

(Reporter: goobsoft, Assigned: p_ch)

Tracking

({helpwanted})

Trunk
helpwanted

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

15 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624

I have a site where there are many shortcuts to speed up UI.  One of my
shortcuts is CTRL+D for deselect all.  Everytime a user uses this it will
bookmark the page.  See the example below:

<HTML>
<HEAD>
  <TITLE>bad</TITLE>
</HEAD>
<BODY>
  If you press CTRL+D you will get an alert indicating that the correct
  function is running, but you will have a bookmark despite the calls to
  event.preventDefault() and event.stopPropagation().
</BODY>
<SCRIPT>
  function KeydownListener() {
    this.handleEvent = function(event) {
      if (event.DOM_VK_D == event.keyCode) {
        if (event.ctrlKey) {
          alert("stopping");
          event.preventDefault();
          event.stopPropagation();
        }
      }
    }
  }
  var useCapture = true;
  var object = document;
  //var object = window;
  object.addEventListener("keydown", new KeydownListener(), useCapture);
  object.addEventListener("keypress", new KeydownListener(), useCapture);
  object.addEventListener("keyup", new KeydownListener(), useCapture);
</SCRIPT>
</HTML>

Reproducible: Always

Steps to Reproduce:
1.
2.
3.

Actual Results:  
the page is bookmarked

Expected Results:  
the page should not be bookmarked
(Reporter)

Comment 1

15 years ago
Created attachment 136625 [details]
The same code in the details
Bookmarks bug -- the bookmark-adding code should not trigger if the event's
default action has been prevented...
Assignee: events → p_ch
Component: DOM: Events → Bookmarks
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: helpwanted
OS: Windows 2000 → All
Hardware: PC → All

Comment 3

15 years ago
The add bookmark triggers on the keypress event with a charCode of DOM_VK_D.
If you prevent that event then the bookmark is not added.
Mozilla does not set the keyCode on a character keypress event.
Nor does preventing the keydown event prevent the keypress event.
Status: NEW → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → INVALID
(Reporter)

Comment 4

15 years ago
You are right.  The last trick is to change the charCode to lowercase.

if (event.DOM_VK_D == (event.charCode & 0xDF)) {
Product: Browser → Seamonkey
You need to log in before you can comment on or make changes to this bug.