Why wont IE fire on paste event?

筅森魡賤 提交于 2021-02-07 17:14:47

问题


I need help figuring out why Internet Explorer won't fire my 'paste' event.

I'm using IE 11. Here is my code:

$(document).on('paste', '.pasteTarget', handlePaste);

When trying this in IE, the function never gets called. It works in chrome.


回答1:


Different browsers treat onpaste differently, or not at all. For IE 11, the latter seems to be the case.


From MDN:

Non-Standard

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Source


Edit: As pointed out in the comments, IE 11 does indeed support onpaste to some extent. However, as this is a non-standard feature, you should be careful about using it in production.




回答2:


You could use beforepaste event instead and access clipboardData from window, not from the event. But, indeed as pointed out already, Clipboard API doesn't seem to be supported in IE: https://developer.microsoft.com/en-us/microsoft-edge/platform/status/clipboardapi/



来源:https://stackoverflow.com/questions/40751786/why-wont-ie-fire-on-paste-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!