pyetterh Posted November 13, 2007 Share Posted November 13, 2007 Hello! I would like to ask for you help. If I have a value stored in $something, how could I copy it automatically to the clipboard (without any help of a button)? Thank you and have a nice day! Peter Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 13, 2007 Share Posted November 13, 2007 you can use the following javascript function <html> <head><title></title></head> <body> <script> function copyToClipboard(s) { if( window.clipboardData && clipboardData.setData ) { clipboardData.setData("Text", s); } else { // You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; // create a transferable var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; // specify the data we wish to handle. Plaintext in this case. trans.addDataFlavor('text/unicode'); // To get the data from the transferable we need two new objects var str = new Object(); var len = new Object(); var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString); var copytext=meintext; 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); } } copyToClipboard("<?=$something?>"); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
pyetterh Posted November 13, 2007 Author Share Posted November 13, 2007 Hello Rajiv! Thank you for your answer. I cannot make it work. Somehow it does not copy the value to the clipboard? Where does the script has to be? In the HEAD, or in the BODY? And my value is stored in this (getting data by PHP): $f00[$n00[1]] Hoping in some resolution... Nice day! Peter Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 13, 2007 Share Posted November 13, 2007 try this <? $something = "test"; ?> <html> <head><title></title></head> <body> <script type='text/javascript'> function copyToClipboard(s) { if( window.clipboardData && clipboardData.setData ) { clipboardData.setData("Text", s); } else { // You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; // create a transferable var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; // specify the data we wish to handle. Plaintext in this case. trans.addDataFlavor('text/unicode'); // To get the data from the transferable we need two new objects var str = new Object(); var len = new Object(); var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString); var copytext=meintext; 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> <script> var well = "<?=$something?>"; copyToClipboard(well); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
pyetterh Posted November 13, 2007 Author Share Posted November 13, 2007 Hi Rajiv! It is not working. The clipboard is empty. I tried to put the script in the HEAD, in the BODY, after the BODY, but nothing. What could be the problem? Peter Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.