Closed Bug 227228 Opened 21 years ago Closed 20 years ago

can not preventDefault() on CTRL+D

Categories

(SeaMonkey :: Bookmarks & History, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: goobsoft, Assigned: p_ch)

Details

(Keywords: helpwanted)

Attachments

(1 file)

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
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
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
Closed: 20 years ago
Resolution: --- → INVALID
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.

Attachment

General

Creator:
Created:
Updated:
Size: