I am trying the copy HTML table element tag with format. I have followed these Stackoverflow answers but still only text is being copy without format.
https://stackoverflow.com/a/38821410 https://stackoverflow.com/a/30566157
Here is my javascript code:
function selectElementContents(el) {
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
document.execCommand("Copy");
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
document.execCommand("Copy");
}
}
This is Copy Table Button
@component('layouts.components.custom-button',
[
'id' => 'copyTable',
'class' => 'ml-auto m-r-10',
'tooltip' => 'Copy Table',
'position' => 'top right',
'target' => '',
'clipboard_target' => '#JoineeTrackerTable',
'toggle' => '',
'action' => '',
'icon' => 'file_copy',
])
@endcomponent
This is Table Code. I am appending Table body content dynamically after constructing it from PHP
<table id="JoineeTrackerTable" class="table table-responsive">
<thead>
<tr class="">
<th class="tablet-hide font-weight-bold c_id">No.</th>
<th>Full Name</th>
<th>Mobile Number</th>
<th class="">Designation</th>
<th class="">Recruiter</th>
<th class="">Country (Recruiter)</th>
<th class="">Organization</th>
<th class="">Process Type</th>
<th class="">Company Name</th>
<th class="">City/Company Site</th>
<th class="">DOI</th>
<th class="">DOJ</th>
<th class="">Joinee Status</th>
<th class="">Job Type</th>
<th class="">Comments</th>
</tr>
</thead>
<tbody id="joinee-tracker-list">
</tbody>
</table>
Any help would be appreciated.