Home > Software design >  copy url to clipboard only some text from link
copy url to clipboard only some text from link

Time:08-02

I am using given below code to copy url, but i am thinking about something different like in given example -- https://oauth2.example.com/code?state=state_parameter_passthrough_value&code=4/0AdQt8qg5KBjhjcHixOZMVfpO4cl_UB8NpoV9-GxBzeiI8xCH_8oqzmYhXvGrAx1SyEFYyQ&scope=https://www.googleapis.com/auth/drive.metadata.readonly

This is the complete url. But i wanted to only copy in clipboard THis ---

4/0AdQt8qg5KBjhjcHixOZMVfpO4cl_UB8NpoV9-GxBzeiI8xCH_8oqzmYhXvGrAx1SyEFYyQ

If this is possible, please somebody guide me.

here the html

 <div >
        <div >
            E-mail address
        </div>
        <div >
            <input type="text"  value="[email protected]" />
            <button><i ></i></button>
        </div>
    </div>

here the java script:

let copyText = document.querySelector(".copy-text");
copyText.querySelector("button").addEventListener("click", function () {
    let input = copyText.querySelector("input.text");
    input.select();
    document.execCommand("copy");
    copyText.classList.add("active");
    window.getSelection().removeAllRanges();
    setTimeout(function () {
        copyText.classList.remove("active");
    }, 2500);
});

CodePudding user response:

Use this code for your Substring

const params = new Proxy(new URLSearchParams(window.location.search), {
      get: (searchParams, prop) => searchParams.get(prop),
    });
    // Get the value of "some_key" in eg "https://example.com/?some_key=some_value"
    let value = params.some_key; // "some_value"
  • Related