Outils pour utilisateurs

Outils du site


Panneau latéral

webdev:javascript:snippets:copy_clipboard

Copying to clipboard

You can select all the text in a textarea, and also fill it with the variable you want before. The textarea need to be visible for the text to be selected, and you can't juste hide it just after.

//////////////////////////////////////
// Javascript
$(document).ready(function() 
{
	$('.copy-ids').on('click', function(e)
	{
		var to_copy = '';

		$('.id_to_copy').each(function(index)
		{	
			to_copy = to_copy + $(this).html() + ' ; ';
		});

		$('.paste-ids').html(to_copy).css('visibility', 'visible');
		$('.paste-ids')[0].select();
		document.execCommand("copy");

		// TODO : indicateur visuel
		
	});
});

//////////////////////////////////////
// HTML
<input class="copy-ids" type="button" value="Copier les ids"/>
<textarea class="paste-ids"></textarea>
webdev/javascript/snippets/copy_clipboard.txt · Dernière modification: 14/12/2018 02:28 de dolo