Skip to main content
deleted 103 characters in body
Source Link
JAAulde
  • 19.5k
  • 5
  • 56
  • 65

I don't know about the code clash--doesn't make sense but I don't have time to test it.

Either way, asAs it is a text input, it seems you'd also have a problem when someone is trying to use the arrow keys to move the cursor within the input. Thus, stopping event propagation/bubbling should be used, and can solve the main issue you're asking about.

// assuming you've grabbed an input in var input_ele input_ele.onkeypress = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; 

Using this will stop the keypress event from leaving the input element, thereby never reaching the document element to trigger the unwanted behavior. In other words, you don't break the expected behavior of a very standard control element.

I don't know about the code clash--doesn't make sense but I don't have time to test it.

Either way, as it is a text input, it seems you'd also have a problem when someone is trying to use the arrow keys to move the cursor within the input. Thus, stopping event propagation/bubbling should be used, and can solve the main issue you're asking about.

// assuming you've grabbed an input in var input_ele input_ele.onkeypress = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; 

Using this will stop the keypress event from leaving the input element, thereby never reaching the document element to trigger the unwanted behavior. In other words, you don't break the expected behavior of a very standard control element.

As it is a text input, it seems you'd also have a problem when someone is trying to use the arrow keys to move the cursor within the input. Thus, stopping event propagation/bubbling should be used, and can solve the main issue you're asking about.

// assuming you've grabbed an input in var input_ele input_ele.onkeypress = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; 

Using this will stop the keypress event from leaving the input element, thereby never reaching the document element to trigger the unwanted behavior. In other words, you don't break the expected behavior of a very standard control element.

Source Link
JAAulde
  • 19.5k
  • 5
  • 56
  • 65

I don't know about the code clash--doesn't make sense but I don't have time to test it.

Either way, as it is a text input, it seems you'd also have a problem when someone is trying to use the arrow keys to move the cursor within the input. Thus, stopping event propagation/bubbling should be used, and can solve the main issue you're asking about.

// assuming you've grabbed an input in var input_ele input_ele.onkeypress = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; 

Using this will stop the keypress event from leaving the input element, thereby never reaching the document element to trigger the unwanted behavior. In other words, you don't break the expected behavior of a very standard control element.