Copy to clipboard using ZeroClipboard - Problem

479 views
Skip to first unread message

Chris

unread,
Mar 24, 2009, 6:51:41 PM3/24/09
to Google Web Toolkit
Hi all,

I've been playing around with the ZeroClipboard (see
http://code.google.com/p/zeroclipboard/) but I did not manage to get
it to work as of now. After having tried out different approaches /
solutions from other users (for example here
http://code.google.com/p/zeroclipboard/wiki/IdeasAndSuggestions), I'm
now asking you guys. =)

I want to copy a calculated value *from within my GWT-application* to
the clipboard so that I can use that value anywhere else using Ctrl-v
(that's what ZeroClipboard is all about right? ;-) )

I therefore put the corresponding code into my host html file
(Application.html) of my GWT-app:
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<title>Application</title>

<script type="text/javascript" language="javascript"
src="ZeroClipbaord.js"></script>
<script language="JavaScript">
function copy() {
var clip = new ZeroClipboard.Client();
clip.setText('Copied!!!');
clip.glue( 'buttonId' );
}
</script>
<script type="text/javascript" language="javascript"
src="GWTServlet.Application.nocache.js"></script>
</head>

<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'
style="position:absolute;width:0;height:0;border:0"></iframe>
</body>
</html>

My corresponding Java source-code looks like this:
public class Application implements EntryPoint {

/**
* This is the entry point method.
*/
public void onModuleLoad() {
FlowPanel table = new FlowPanel();

table.getElement().setId("FlowPanel");

Button button = new Button("ClickMe to copy to clipboard");
button.getElement().setId("buttonId");
button.addClickListener(new ClickListener(){

public void onClick(Widget arg0) {
copyInJava();
}

});
table.add(button);

RootPanel.get().add(table);
}

public native void copyInJava() /*-{
$wnd.copy();
}-*/;
}

ZeroClipboard works just fine when used in plain HTML to copy contents
to the clipboard but I did not manage to get it to work from inside a
GWT-application.

I also used FireBug to debug and apparently there is some issue when
creating the ZeroClipboard.Client() object. Nonetheless, when I run it
in plain HTML, everything is fine so I assume that the issue is due to
the fact that I'm using a GWT-app to get the job done.

Does anybody have suggestions what the problem might be?

Cheers

Thomas Broyer

unread,
Mar 24, 2009, 8:50:34 PM3/24/09
to Google Web Toolkit


On 24 mar, 23:51, Chris <zae...@gmail.com> wrote:
> Hi all,
>
> I've been playing around with the ZeroClipboard (seehttp://code.google.com/p/zeroclipboard/) but I did not manage to get
> it to work as of now. After having tried out different approaches /
> solutions from other users (for example herehttp://code.google.com/p/zeroclipboard/wiki/IdeasAndSuggestions), I'm
My understanding of ZeroClipboard is that your copy() function should
be called *prior* to clicking the button, so that ZeroClipboard can
overlay a transparent Flash movie over the button; when you click the
button, you actually click the Flash movie which copies the given text
into the clipboard (that's click-jacking).

So with your code, on the first click you "install" the ZeroClipboard
client and starting with the second click only you copy the text to
the clipboard.
Reply all
Reply to author
Forward
0 new messages