John Davidson

javascript - Create Copy clipboard

0 comments
Message:


I want to make a clone of node to get the UID encrypting the data into the clipboard. I got the id from the internal server but I don't know how to clone the node so it understands the correct location it copied.



<div class="container">
<div class="wrapper" id="form-inf">
<h3>Information</h3>
<a href="../form_inf_sv/index.php" class="btn btn-info" role="button">Import UID</a>
<a href="./index.php" class="btn btn-secondary" role="button">Select</a>
<table style="width:100%" class="form-main-table">
<tr>
<th>STT</th>
<th>ID</th>
<th>UID</th>
<th>Day Create</th>
<th>Action</th>
</tr>
<?php
require '../connect/connect.php';
// $sql = "SELECT * FROM category";
$sql = "DELETE FROM tbl_new_uid WHERE cd_del=1";
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error deleting record: " . $conn->error;
}
$sql = "SELECT * FROM tbl_new_uid ORDER BY date_create DESC";
$result = $conn->query($sql) or die($conn->error);
$stt = 1;
while($row = $result -> fetch_assoc()){
?>
<tr>
<td><?=$stt++?></td>
<td><?=$row['id']?></td>
<td id="inf_copy"><?=$row['uid_new']?></td>
<td><?=$row['date_create']?></td>
<td><a href='#' class="btn btn-info" style="width: 100px;">Edit</a>
<a href='./config/delete.php/?id=<?=$row['id']?>' class="btn btn-success" style="width: 100px;">Delete</a>
<button id="btn_copy" class="btn btn-warning" style="width: 100px;">Copy</button></td>
</tr>
<?php }
$conn->close();
?>
</table>
</div>
</div>
<script>
// setTimeout('window.location.reload();',3000);
</script>
<script>
$('#btn_copy').on('click', function() {
var text = $('#inf_copy').html();
var tempElement = $('<input>').val(text).appendTo('body').select();
document.execCommand('copy');
tempElement.remove();
var elem = document.getElementById("inf_copy");
elem.style.background = "yellow";
elem.style.fontWeight = "bold";
});
</script>


My Answer:
To create a copy of a node and encrypt the data into the clipboard, you can follow these steps:

1. Get the node that you want to clone using its ID:
javascript
const originalNode = document.getElementById('yourNodeId');


2. Create a deep clone of the node:
javascript
const clonedNode = originalNode.cloneNode(true);


3. Encrypt the data in the cloned node:
javascript
// Add your encryption logic here


4. Create a new textarea element to hold the encrypted data:
javascript
const textarea = document.createElement('textarea');
textarea.value = clonedNode.innerHTML;
document.body.appendChild(textarea);


5. Select the text in the textarea and copy it to the clipboard:
javascript
textarea.select();
document.execCommand('copy');


6. Remove the textarea element from the DOM:
javascript
document.body.removeChild(textarea);


Now, the encrypted data from the cloned node should be copied to the clipboard. Make sure to add your encryption logic in step 3 to encrypt the data before copying it.

Rate this post

5 of 5 based on 6003 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us