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
https://forums.phpfreaks.com/topic/77111-autocopy-to-clipboard/#findComment-390521
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
https://forums.phpfreaks.com/topic/77111-autocopy-to-clipboard/#findComment-390534
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
https://forums.phpfreaks.com/topic/77111-autocopy-to-clipboard/#findComment-390538
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.