0

I want that when page load it auto copy the copy to clipboard

Please check the code not working

<body onload=attachFlash('ppp')>



function attachFlash(code) {
var clip = new ZeroClipboard.Client();
   var myTextToCopy = code;
clip.setText(myTextToCopy);

clip.glue(code);
}
user1129464
  • 21
  • 1
  • 3
  • Unless this is for use in an internal application, I'd recommend against this - it's discourteous to your users to overwrite whatever was in their clipboard without warning. Also, have you [read the docs](https://github.com/zeroclipboard/ZeroClipboard)? `...Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie. This is achieved by automatically floating the invisible movie on top of a DOM element of your choice` - so it needs a click in Flash 10+ for it to work – Basic Aug 15 '13 at 07:34

1 Answers1

0

As mentioned in the comments, this requires a user interaction.

I recommend having a div with this style.

.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    text-align: center;
    background: rgba(255, 255, 255, .5);
}

Bind zero clipboard to that, and instruct the user to click to copy the text and continue. Users should always be notified of their clipboard modifications. If you end up replacing their college thesis with some arbitrary text, without warning, they might not be so happy...

Brigand
  • 84,529
  • 20
  • 165
  • 173