last day (14 days later) » 

4:50 PM
3
A: jQuery click button copy to clipboard

Alvaro MontoroThere is another non-Flash way (apart from the Clipboard API mentioned in jfriend00's answer). You need to select the text and then execute the command copy to copy to the clipboard whatever text is currently selected on the page. For example, this function will copy the content of the passed el...

 
strange ... here it works, but I cannot get to work it locally 0o jquery-1.11.3 Chrome 43.0.2357.130 (64-bit)
 
Do you get any error on the console?
 
I've removed $("#temp").remove(); and perform in console (after copyToClipboard triggered) $("#temp").val($('body').text()).select(); > [<input type=​"text" id=​"temp" style=​"position:​absolute;​opacity:​0;​">​] document.execCommand("copy"); > false
seems select() problem because document.execCommand("copy") works after selecting some text on page manually
 
Do you have any element with id #temp already on the page?
 
nope it is only one (after remove() $('#temp') -> nothing)
 
4:50 PM
This is strange. Does it work if you assign it a string instead of doing $('body').text()?
 
nope it doesn't work ... looking for another way to select
 
@madzohan Ok, I was able to reproduce the issue. It is weird because I was only able to reproduce it on local (file://) on 64-bit Chrome. I also found a quick solution that works for me: using plain JavaScript instead of jQuery. I will update the answer with that code. Please check it and let me know if it works for you.
 
thanks, but anyway it doesn't work :D works only in chain document.execCommand("SelectAll"); document.execCommand("Copy"); maybe you know how to select window.location.href without any temp manipulations?
 
Hello =)
 
4:51 PM
I'm intrigued about that error
I even uninstalled the 32-bit to install the 64-bit Chrome version
 
I have teamviewer if you want to take a look :D
 
if you could share the code here
 
it is a django project =) with dynamic ajax parts ... your snippet I've tried in bootstrap modal (created dynamically)
anyway now I will try Safary
*safari
 
Oh ok
I thought it was going ot be a small snippet :(
did you get it working with SelectAll?
 
0o safari crashes xD
 
5:01 PM
Safari doesn't support execCommand
at least not yet
 
it crashes loading startpage ... i've figured out why - SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' if you familiar with django
 
Not really :(
I don't think I'll be able to assist with this one
 
document.execCommand('SelectAll');
document.execCommand("Copy"); works in safari
))
8.0.4 (10600.4.10.7)
ok thanks anyway =) seems I need flash solution :\
 
Sorry
But thanks for your feedback
I will update the answer with this information
 
=) bye
 
5:11 PM
bye
 

last day (14 days later) »