Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Compose HTML Paste in Javascript

I'm using an HTML DIV in Content Editable mode. From Javascript, given a valid image URL in a string, how can I convert that into something that I can push onto the clipboard so that when I paste into the Content Editable DIV with CTRL+V keystroke, it pastes the image itself and not the plain text string?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

async function writeClipImg(url) {
  try {
    const data = await fetch(url);
    const blob = await data.blob();
    await navigator.clipboard.write([new ClipboardItem({
      [blob.type]: blob
    })]);
    console.log('Fetched image copied.');
  } catch (err) {
    console.error(err.name, err.message);
  }
}
//function from https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem
let text; //get somehow the text of the div
if (text.indexOf('://') != -1) { //check 'https://' (typic url substring) is there at the text
  //only the https care - you can write this for http://, file:///, data etc.
  let link = text.slice(text.indexOf('https://'), text.indexOf(' ', text.indexOf('https://')))
  //its only get the first link
  writeClipImg(link)
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda