Copy Code code as follows:
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "Keywords" content= "yes! B/s! "/>
<meta name= "Description" content= "This page was from http://Justinyoung.cnblogs.com"/>
<title>css/javascript demo</title>
<script type= "Text/javascript" language= "JavaScript" >
function Test () {
CopyToClipboard ("dddd");
}
CopyToClipboard = 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 ("Your Firefox security restrictions restrict your clipboard operations, please open ' about:config ' to Signed.applets.codebase_principal_support ' set to True ')";
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);
}
}
</script>
<body>
<button onclick= "Test ();" > Copy to Pasteboard </button>
</body>
Description: Firefox's default security restrictions do not allow JavaScript to be copied to the Clipboard, you need to prompt the user to modify Firefox settings. The modification method is to open "About:config" to set "Signed.applets.codebase_principal_support" to "true".