<script type="text/javascript">
window.onload = function(){
document.getElementsByName('copy')[1].onclick = function(){
var text = document.getElementsByName('copy')[0].value;
if(window.clipboardData) window.clipboardData.setData("Text", text); //IE
else if(window.netscape) { //Netscape
try {
if(netscape.security.PrivilegeManager.enablePrivilege)
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
//netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite")
}
catch(event) {
alert('Настройка безопасности браузера не позволяет обращаться к буферу обмена!\n'+event);
return;
}
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 = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString),
copy = text;
str.data = copy;
trans.setTransferData("text/unicode", str, copy.length*2);
if(!clip) return false;
clip.setData(trans, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
}
alert("В буфер обмена сохранено:\n" + text);
return false;
};
};
</script>
<input type="text" value="text" name="copy" />
<input type="submit" value="copy" name="copy" />