I have overridden the paste
event. I noticed that because the event's default behavior is prevented, it is not currently possible to undo the "paste" with Ctrl+Z.
$(this).on('paste', function (evt) {
// Get the pasted data via the Clipboard API.
// evt.originalEvent must be used because this is jQuery, not pure JS.
// https://stackoverflow.com/a/29831598
var clipboardData = evt.originalEvent.clipboardData || window.clipboardData;
var pastedData = clipboardData.getData('text/plain');
// Trim the data and set the value.
$(this).val($.trim(pastedData));
// Prevent the data from actually being pasted.
evt.preventDefault();
});
Is there a way to override the undo functionality or do the above differently such that Ctrl+Z will work?
Related questions
- JavaScript get clipboard data on paste event (Cross browser)
- Paste event modify content and return it at the same place
from Undo an overridden paste in JS
No comments:
Post a Comment