Jagadeesh
Jagadeesh

Reputation: 2800

How to implement copy to clip board functionality in GWT for FireFox browser

I could able to achieve copy to clipboard on button click in IE with following code snippet.

PFB the JSNI method:

private static native void copyTextToClipBoard(UIObject panel) /*-{
    var frame = $doc.getElementById('__printingFrame');
    if (!frame) {
        $wnd.alert("Error");
        return;
    }
    frame = frame.contentWindow;
    var doc = frame.document;
    doc.open();
    doc.write(panel);
    if (doc.body != null) {
        var r = doc.body.createTextRange();
        r.execCommand('copy');
    } else {
        return alert("Only Internet Explorer will support this action");
    }
}-*/;

But as we know this code will never work for FireFox. Is there any way that we could achieve this behavior in FireFox.

Upvotes: 0

Views: 942

Answers (2)

Eliran Malka
Eliran Malka

Reputation: 16263

Well,

if ("your clients simply cannot have flash installed" && 
        "you must have them copying and pasting all around") {
    if (they("configure firefox to enable javascript access to the clipboard")
            .seeBelow()) {
        you("can implement a solution in javascript, and wrap it with JSNI");
    } else {
        they("must install a firefox addon for that purpose, there are plenty"); 
    }
} else {
    just("go with flash, man");
}

See how to enable clipboard access for javascript (by editing user.js).

Upvotes: 3

Kaushik
Kaushik

Reputation: 3381

Take a look at ZeroClipboard. You can probably use JSNI to inject a piece of code as in the examples in the link.

Upvotes: 1

Related Questions