Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto copy to the clipboard when a button is clicked in Rails 3?

I am developing an application in Rails 3 where I have a text field which contains a URL:

 <input type="text" readonly="readonly" value="<%= linkbunch_url(@link.link) %>" class="span4" id="url_copy" />

Next to this I have a button:

<button type="button" id="copy_link" class="btn btn-success"><i class="icon-share" ></i>&nbsp;&nbsp; Copy To ClipBoard</button>

When someone clicks on this button, I want the url in the text field to be copied into the clipboard. How do I do this?

like image 593
Siddharth Avatar asked Sep 21 '25 10:09

Siddharth


1 Answers

There is no way to do that with Ruby through the web browser.

You need a JavaScript method instead. Look at "How to copy to the clipboard in JavaScript?".

like image 96
VadimAlekseev Avatar answered Sep 23 '25 00:09

VadimAlekseev