Jump to content
Fórum Script Brasil
  • 0

Como copiar conteúdo de duas div's ao mesmo tempo?



É o seguinte, com o código abaixo só consigo escolher uma das divs, eu quero clicar no botão de copiar e copiar as duas divs, com um clique só...

<div id="markup">
  Text that can be copied or selected with cross browser support.
não copiar esse texto
<div id="markup2">
  Copiar o texto 2

<button id="botaodecopiar1">copiar!</button>

E o javascript

<script type="text/javascript">
        function selectElementContents(el) 
    // Copy textarea, pre, div, etc.
	if (document.body.createTextRange) {
        // IE 
        var textRange = document.body.createTextRange();
	else if (window.getSelection && document.createRange) {
        // non-IE
        var range = document.createRange();
        var sel = window.getSelection();
        try {  
		    var successful = document.execCommand('copy');  
		    var msg = successful ? 'successful' : 'unsuccessful';  
		    console.log('Copy command was ' + msg);  
		} catch(err) {  
		    console.log('Oops, unable to copy');  
} // end function selectElementContents(el) 

function make_copy_button(el)
	var botaodecopiar = document.getElementById('botaodecopiar1');
	botaodecopiar.onclick = function() { selectElementContents(el); };
	if (document.queryCommandSupported("copy") || parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 42)
		// Copy works with IE 4+, Chrome 42+, Firefox 41+, Opera 29+
		botaodecopiar.value = "Copy to Clipboard";
		// Select only for Safari and older Chrome, Firefox and Opera
		botaodecopiar.value = "Select All (then press CTRL+C to Copy)";
var elem = document.getElementById("markup");
var elem2 = document.getElementById("markup2");


Link to comment
Share on other sites

1 answer to this question

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.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...