0

我可以使用以下代码片段在 IE 中单击按钮时实现复制到剪贴板。

PFB JSNI 方法:

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");
    }
}-*/;

但正如我们所知,这段代码永远不会适用于 FireFox。有什么方法可以在 FireFox 中实现这种行为。

4

2 回答 2

3

出色地,

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");
}

了解如何启用对 javascript 的剪贴板访问(通过编辑user.js)。

于 2013-07-09T20:41:05.637 回答
1

看看ZeroClipboard。您可能可以使用 JSNI 注入一段代码,如链接中的示例所示。

于 2013-07-09T07:40:29.203 回答