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

98
Views
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 answers
Answer question

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 Report
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!