Click here to Skip to main content
15,891,712 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using this plugin for copy to clipboard.

https://github.com/zeroclipboard/ZeroClipboard[^]

But I want it to do without clicking on a button.

I want it to do when the page load, it automatically copy the text from the url param to clipboard.

Is there a way to do it?

Here's my code but not working:

<script type="text/javascript" src="/js/ZeroClipboard.js"></script>
	<script type="text/javascript">
	$(document).ready(function () {
		var key = GetURLParameter('key');
		//alert(key);
		
		var clip = new ZeroClipboard( window.onload, {
			moviePath: "/js/ZeroClipboard.swf"
		} );
		
		clip.on( 'load', function(client) {
			copy: key
		} );
	});
	
	function GetURLParameter(sParam)
	{
		var sPageURL = window.location.search.substring(1);
		var sURLVariables = sPageURL.split('&');
		for (var i = 0; i < sURLVariables.length; i++) 
		{
			var sParameterName = sURLVariables[i].split('=');
			if (sParameterName[0] == sParam) 
			{
				return sParameterName[1];
			}
		}
	}
	</script>
Posted
Updated 25-Jul-13 8:32am
v2
Comments
ZurdoDev 25-Jul-13 15:12pm    
I would put a breakpoint and see what is happening.
Ganesan Senthilvel 25-Jul-13 21:16pm    
did you debug at client side (like firebug at FireFox browser)

1 solution

1.add listener to "ctrl+c"
2.get content from clipboard
3.set the content there where you want to palce

JavaScript
var ctrl = false;
$(function(){
    $('.cf').keydown(function(e){
        if(e.keyCode==17)
        {
            ctrl = true;
        }
    });
    $('.cf').keyup(function(e){
        if(e.keyCode==17)
        {
            ctrl = false;
        }
        if(ctrl && e.keyCode==86)
        {
            var text = $(this).val();
            MyChaiFei(text,$(this));
        }
    });
})
function MyChaiFei(text,jqobj)
{
    jqobj.focus();

    jqobj.val(text);
}



HTML
<input type="text" class="cf" />
<input type="text" class="cf" />
<input type="text" class="cf" />
<input type="text" class="cf" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900