1

I'm stuck with Copy and paste. I want to copy the content inside the modalBody below.

Here is my condition

  1. Some Text with an image file that is consist of some byte.
  2. click a button to copy them <----(this is what I want to do)

Is there any way to select them all and copy them?

Please give me some advice to solve this issue.

...
...


  useEffect(() => {
    axios
      .get(`api/v1/download_mms?id=4226`)
      .then((res: any) => {
        console.log('The response: ', res);

        if (res.data.code === 200) {
          setDetailData(res.data.data);
        } else {
          alert('error');
        }
      })
      .finally(() => {});
  }, []);

  return (
    <CModal show={modal} onClose={() => setModal(!modal)} size="">
      <CForm>
        <Detail>
          <CModalHeader>
            <CModalTitle>barCode Info </CModalTitle>
          </CModalHeader>

          <CModalBody>
            <div>
              <text>{detailData.box_barcode}</text>

              <img
                //detailData.byteImage
                src={`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJsAAAABAQAAAADh5+EEAAAAHklEQVR42mP4mZySrqo8eyOX58mZxmo5qdPnBD8AAFxECQFLyfS0AAAAAElFTkSuQmCC`}
              />
            </div>
          </CModalBody>

          <CModalFooter>
            <CButton color="primary" onClick={() => copyTheModalBodyInfo()}>
              clck to Copy
            </CButton>

            <CButton color="primary" onClick={() => setModal(!modal)}>
              Close
            </CButton>
          </CModalFooter>
        </Detail>
      </CForm>
    </CModal>
  );
}


Jin Park
  • 371
  • 1
  • 9
  • 23
  • Do you want to copy text on click of some button? See [Copy text from a div to clipboard using document.execCommand in React](https://stackoverflow.com/a/67032810/2873538). Try `Document.execCommand`. – Ajeet Shah Jun 11 '21 at 03:31
  • on button click event, it has to be copied some text with the img. is there any way to select all that div side the CModalbody and perform the Document.execCommand('copy')? – Jin Park Jun 11 '21 at 03:50

0 Answers0