Clipboard.js: data-clipboard-text is not being copied in Chrome 55

Created on 23 Feb 2017  Â·  8Comments  Â·  Source: zenorocha/clipboard.js

Minimal example

I have a link:

<a id="copy-button" class="btn" data-clipboard-text="test">
      <i class="icon-chain"></i><span>copy me</span>
</a>
<script>
copyToClipboard('copy-button');
</script>

and JS:

function copyToClipboard(copyButtonId){
    var clipboard = new Clipboard('#'+copyButtonId);
    clipboard.on('success', function(e) {
        console.info('Action:', e.action);
        console.info('Text:', e.text);
        console.info('Trigger:', e.trigger);
    });
}

When I click the link, console prints:

Action: copy
Text: test
Trigger: <a id=​"copy-button" class=​"btn" data-clipboard-text=​"test">​…​</a>​

Expected behaviour

Content test should be inside clipboard

Actual behaviour

clipboard has previously copied value

Browsers affected

Chrome 55.0.2883.87
Firefox 51.0.1

Most helpful comment

Check the new container option introduced by #368 on v1.7.0

All 8 comments

Clipboard.js is working fine. The problem is how you're using JavaScript.

In this line:

copyToClipboard(copy-button)

You forgot to add the quotes.

copyToClipboard('copy-button')

If you still have a problem, please share a JSFiddle.

@zenorocha
Of course I'm using quotes.
Look what console prints in my example. It wouldn't work otherwise...
Could you please reopen it?

I'm experiencing the same on the newest version of Chrome and the newest version of this library. @eximius313 Any resolution on this?

https://clipboardjs.com/ uses data-clipboard-text and everything seems to be working fine.

Can you share a JSFiddle that reproduces this problem?

I discovered that it has something to do with modal window because if the button is on the window's "parent" page - copying works fine. If it is inside the window - it doen't work.
Unfortunatelly I didn't have the problem solved yet

Check the new container option introduced by #368 on v1.7.0

It works! Thank you

;D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michael-letcher picture michael-letcher  Â·  3Comments

XZZsr picture XZZsr  Â·  5Comments

bravo14 picture bravo14  Â·  3Comments

flydev-fr picture flydev-fr  Â·  3Comments

hassaanrana picture hassaanrana  Â·  6Comments