我可以使用以下代码片段在 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 中实现这种行为。