Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

666
Views
Simule la pulsación de tecla (ctrl+v) y envíe KeyboardEvent a un div en Angular2 o JavaScript

tengo un div:

 <div class="paste-area-content" #pasteDiv contenteditable="true" (paste)="onPaste($event)" (input)="unsupportedBrowserPaste()"> </div>

Si el foco está en él y presiono Ctrl + V , luego llamo a la función onPaste con un ClipboardEvent y etc., la imagen del portapapeles aparece en el div .

Ahora me gustaría usar un <button> para hacer el mismo proceso. Así que pensé en simular la keypress de tecla cuando se hace clic en el botón y enviar KeyboardEvent al div.

Probé muchas soluciones similares, pero ninguna funcionó o simplemente están obsoletas. El último intento fue:

 var event = new KeyboardEvent('keypress', { bubbles: true, cancelable: true, ctrlKey: true, key : "v", code : "86" }); this.printedArticleImagePasteComponent.simulatePaste(event); public simulatePaste(event: KeyboardEvent) { this.pasteDiv.nativeElement.dispatchEvent(event); }

No funciona, por supuesto. ¿Cómo es posible solucionar esto?

La segunda idea fue: obtener la imagen del portapapeles, crear un ClipboardEvent manualmente, configurar ClipboardEvent.clipboardData.items . Pero window.clipboardData.getData no funciona.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!