我可以通过以下代码片段在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中实现这种行为。
答案 0 :(得分: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");
}
请参阅how to enable clipboard access for javascript(通过修改user.js
)。
答案 1 :(得分:1)
看看ZeroClipboard。您可以使用JSNI注入一段代码,如链接中的示例所示。