0

Is it possible to copy the query of a form, which is using GET method, to the clipboard?

Link

My aim is to have a button, which when pressed should copy the value in the black box to the clipboard so it is easily shared with someone else.

Edit: Not just asking about copying something into the clipboard, I am also asking about how to get the value of the GET query..

JKaw
  • 83
  • 2
  • 9
  • 2
    Possible duplicate of [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Ele Feb 04 '18 at 18:16
  • @Ele No it is not. I want to get the value of a **GET query** to the clipboard – JKaw Feb 04 '18 at 18:17
  • Can you explain why not? – Ele Feb 04 '18 at 18:18
  • Because I am asking about how to get the value of the query not just how to copy to the clipboard – JKaw Feb 04 '18 at 18:20
  • Regex will be the wae. – Jakub Chlebowicz Feb 04 '18 at 18:21
  • what do you mean by the black box..What is it?? – Uzair Feb 04 '18 at 18:23
  • @Uzair Did I upload the photo incorrectly? https://i.stack.imgur.com/Fp26W.png The blackbox contains the "website"/"php file"?"Value of GET" and I want to copy the whole thing into the clipboard. Or if that's not possible to a text field where the user can copy it themselves. – JKaw Feb 04 '18 at 18:27

2 Answers2

2

The GET parameters are only added to the submitted URL at the moment where the button is pressed, i.e. the form is submitted, so I don't think that 's possible directly (i.e. retreiving a value from the submit button)

But you could use a plugin like https://clipboardjs.com/, "collect" all the form data via JS and combine them together with the initial URL for its return value including the GET data.

Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Ah, though it would be easy. However, thanks for the link I will see if I can get it to work the way I want it to! – JKaw Feb 04 '18 at 18:29
0

this might help

var path = location.href.replace(/[^\?]+$/,$('form').serialize());
var cpy = $('input#cpy').val(path);
    cpy.select(); 
    document.execCommand('copy');
hariaon
  • 26
  • 3