The paste event in browsers

February 15, 2019|
1 min read
  • javascript

Originally posted by me on Hashrocket TIL

Browsers allow you to capture a paste event in a DOM element [1] [2].

This event fires before any clipboard data is inserted into the document, which makes it ideal for manipulating the data and pasting the manipulated data instead.

In Today I Learned by Hashrocket we recently utilized this feature to enable pasting images straight into the post editor. The image is then uploaded to imgur.com and the resulting URL is pasted as a Markdown Image Tag into the textbox.

image

If you are interested in adding similar functionality to your site check out this PR.

Also consider hosting your own fork of TIL.


© 2023, Dorian Karter