I tried but it's not perfect.
public function q_view_buttons($q_view) { $page_url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $this->output ('<input type="text" value="'.$page_url.'" id="myInput" style="width:1px; height:1px">'); <button type="button" onClick="myFunction(); return false;" style="margin-left:-10px;z-index:999;"> $this->output ('<script src="../script/copylink.js"></script>'); qa_html_theme_base::q_view_buttons($q_view); }
And the script:
function myFunction() { /* Get the text field */ var copyText = document.getElementById("myInput"); /* Select the text field */ copyText.select(); copyText.setSelectionRange(0, 99999); /*For mobile devices*/ /* Copy the text inside the text field */ document.execCommand("copy"); /* Alert the copied text */ alert("Link copied: " + copyText.value); }
Not sure why it doesn't work on mobile phones!!!
Btw, it seems that Firefox doesn't allow URL to be copied from hidden input.
Who can detect how this site has a nice "copy link" function ? https://www.proprofs.com/discuss/q/54163/what-is-the-full-form-of-ok
Welcome to the Q&A site for Question2Answer.
If you have a question about Q2A, please ask here, in English.
To report a bug, please create a new issue on Github or ask a question here with the bug tag.
If you just want to try Q2A, please use the demo site.