function getClipboard() {
if (window.clipboardData) {
return window.clipboardData.getData("text");
} else {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) {
return;
}
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) {
return;
}
trans.addDataFlavor("text/unicode");
clip.getData(trans, clip.kGlobalClipboard);
var str = new Object;
var len = new Object;
trans.getTransferData("text/unicode", str, len);
} catch (e) {
alert("\u60A8\u7684firefox\u5B89\u5168\u9650\u5236\u9650\u5236\u60A8\u8FDB\u884C\u526A\u8D34\u677F\u64CD\u4F5C\uFF0C\u8BF7\u6253\u5F00'about:config'\u5C06signed.applets.codebase_principal_support'\u8BBE\u7F6E\u4E3Atrue'\u4E4B\u540E\u91CD\u8BD5\uFF0C\u76F8\u5BF9\u8DEF\u5F84\u4E3Afirefox\u6839\u76EE\u5F55/greprefs/all.js");
return null;
}
if (str) {
if (Components.interfaces.nsISupportsWString) {
str = str.value.QueryInterface(Components.interfaces.nsISupportsWString);
} else {
if (Components.interfaces.nsISupportsString) {
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
} else {
str = null;
}
}
}
if (str) {
return str.data.substring(0, len.value / 2);
}
}
}
return null;
}
var copy2Clipboard = function (txt) {
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
} else if (navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("\u60A8\u7684firefox\u5B89\u5168\u9650\u5236\u9650\u5236\u60A8\u8FDB\u884C\u526A\u8D34\u677F\u64CD\u4F5C\uFF0C\u8BF7\u6253\u5F00\u2019about:config\u2019\u5C06signed.applets.codebase_principal_support\u2019\u8BBE\u7F6E\u4E3Atrue\u2019\u4E4B\u540E\u91CD\u8BD5\uFF0C\u76F8\u5BF9\u8DEF\u5F84\u4E3Afirefox\u6839\u76EE\u5F55/greprefs/all.js");
return false;
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) {
return;
}
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) {
return;
}
trans.addDataFlavor("text/unicode");
var str = new Object;
var len = new Object;
var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData("text/unicode", str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip) {
return false;
}
clip.setData(trans, null, clipid.kGlobalClipboard);
}
}
document.body.oncopy = function () {
setTimeout( function () {
var text = getClipboard();
if (text) {
text = text + "\r\n详细出处参考:"+document.location.href;
copy2Clipboard(text);
}
}, 100 )
}