Jump to content

AUTOCOPY TO CLIPBOARD


pyetterh

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.