Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:05:30+00:00 2026-05-26T23:05:30+00:00

given a content editable div. How can I detect a paste event, prevent the

  • 0

given a content editable div. How can I detect a paste event, prevent the paste from being inserted so can I can intercept and sanitize the paste to include text only?

I also don’t want to lose focus after the paste + sanitize is complete.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:05:30+00:00Added an answer on May 26, 2026 at 11:05 pm

    UPDATE:

    All major browsers now give you access to the clipboard data in a paste event. See Nico Burns’s answer for an example on newer browser and also check out Tim Down’s answer if you need to support older browsers.


    You can listen for the onPaste event on the div to detect the paste. If you just want to disable the paste you can call event.preventDefault() from that listener.

    To capture the pasted content however is a little bit more difficult since the onPaste event does not give you access to the pasted content. The usual way to handle this is to do the following from the onPaste event handler:

    • create a dummy div and place it outside the window boundaries so it’s not visible to visitors
    • move the focus to this div
    • call a sanitizer method using a setTimeout(sanitize, 0)

    and from your sanitizing method:

    • find the dummy div and get it’s contents
    • sanitize the HTML and remove the div
    • move the focus back to the original div
    • insert the sanitized content in the original div
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get a MIME Content-Type from a given extension (preferably without accessing
Given this editable DIV: <div contenteditable> First line Second line Third line Fourth line
I've been given the task of content migration from another CMS system to SharePoint
I wish to display content depending on the given role(s) of the active user
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Given the following html: <tr> <td>Content</td> <td>Content</td> <td>Content</td> <td><img id=imgProductPurchased runat=server visible=true alt=Product Purchased
I am using the excellent jTemplates plugin to generate content. Given a data object
Given a contentEditable div like so: <div contenteditable=true>Here is some text, hello world.</div> How
I am trying to use jQuery to find <td> s with given content (text)
Is there a library which allows determining whether a given content type is binary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.