0

js and now I am trying to copy my input value text to my clipboard. I write some code but it not working, please help me figure out and correct my code.

      import InputBox from "./Input"
      import ButtonBox from "./Button"

      const EarlyAccessLimitation = () => {
      let urlAddress = window.location;

      function copyURLToClipboard() {
        const UrlText = urlAddress;
        UrlText.select();
        alert.execCommand("copy");
      }
      return (

        <div>
             <InputBox url={urlAddress} />
             <ButtonBox onClick={copyURLToClipboard}/>
       </div>
      );
    };

    export default  EarlyAccessLimitation ;

It not show any error, but also it not copy the text.

  • You seem to be trying to call `.select()` on a string. The string has to be part of the DOM for this method to work, and you need to select the element. This answer covers pretty much all aspects of JS clipboard control: https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript – DBS May 31 '20 at 15:12
  • I was very grateful if you show me how can I modify my code, thanks – Vardan Hambardzumyan May 31 '20 at 15:41

0 Answers0