Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Saving HTML Element to Clipboard Giving Error

I have written some code to copy a hyperlink to the clipboard in HTLM format, however it's giving me an error.

  copyLink() {
    let theInput = "<a href='www.google.com'>This is a test</a>";
    let item: ClipboardItem = new ClipboardItem({'text/html': theInput});
    let clipboard: any = navigator.clipboard;
    clipboard.write([item]);
  }

When the code is ran I get this: enter image description here

Can anyone explain why?

I'm using an older version of angular with an older version of typescript so I had to add these interface definitions to the top of my file to get it to compile.

interface ClipboardItem {
  readonly types: string[];
  readonly presentationStyle: "unspecified" | "inline" | "attachment";
  getType(): Promise<Blob>;
}

interface ClipboardItemData {
  [mimeType: string]: Blob | string | Promise<Blob | string>;
}

declare var ClipboardItem: {
  prototype: ClipboardItem;
  new (itemData: ClipboardItemData): ClipboardItem;
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

ClipboardItem expects a Blob as value for the MIME-Type

Source (See Constructor): https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem

const myHTMLString = "<a href='www.google.com'>This is a test</a>";
const myBlob = new Blob([ myHTMLString ], {type: 'text/html'});
let item = new ClipboardItem({'text/html': myBlob });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda