How to copy div content form div to clipboard
Code Behind File :
Create string builder with some content and assign as like
divcontent.InnerHtml = sbQuestionAndAnswers.ToString();
Design File:
ย <div id=”divcontent” style=” width: 1px; height: 1px;overflow:hidden;” runat=”server”></div>
Script File :
if (window.clipboardData && clipboardData.setData) {
if ($(‘#ctl00_cphMain_divcontent’)) {
$(‘#ctl00_cphMain_divcontent’).show();
var editableDiv = $(‘#ctl00_cphMain_divcontent’)
[0];
var txtRange = document.body.createTextRange();
editableDiv.style.display = “”;
txtRange.moveToElementText(editableDiv);
txtRange.select();
txtRange.execCommand(“Copy”);
editableDiv.style.display = “none”;//Hide the div
}}
var txtRange = document.body.createTextRange();
editableDiv.style.display = “”;
txtRange.moveToElementText(editableDiv);
txtRange.select();
txtRange.execCommand(“Copy”);
editableDiv.style.display = “none”;//Hide the div
}}
Note :
Copying the content of div which is bind dynamically form code-behind and it will not display in the page. From that we copy content to clipboard
Leave A Comment