- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019 10:29 PM
Hi All,
I am having the requirement where I need to copy the text filed value to clipboard when I click on the Copy button. Does anyone come across similar requirement and implemented.
HTML Code :
<a href="{{::item.URL}}" target="_blank"> <input id="copyurl" type="text" value={{::item.URL}} class="form-control" readonly></a>
<div class="input-group-btn">
<button ng-click="Copy()" class="btn btn-default" >${Copy}</button>
</div>
Client script :
$scope.Copy = function() {
copyurl.select();
document.execCommand("copy");
}
Thanks,
Akhil
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2019 01:54 AM
Below code works.
$scope.Copy = function(item) {
var v = document.createElement('textarea');
var copyText=item.URL;
v.innerHTML = copyText;
document.body.appendChild(v);
v.select();
var result = true;
try {
result = document.execCommand('copy');
}
catch(err){
result = false;
}
finally{
document.body.removeChild(v);
}
if(result === true){
spUtil.addInfoMessage("Text copied to clipboard");
}
else{
$window.prompt("${Because of a browser limitation the URL can not be placed directly in the clipboard. Please use Ctrl-C to copy the data and escape to dismiss this dialog}", permalink);
}
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019 11:10 PM
Hi Satish,
There is some problem with
Getting error : TypeError: Cannot read property 'empty' of undefined
at ChildScope.$scope.Copy
document.selection.empty();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2019 01:54 AM
Below code works.
$scope.Copy = function(item) {
var v = document.createElement('textarea');
var copyText=item.URL;
v.innerHTML = copyText;
document.body.appendChild(v);
v.select();
var result = true;
try {
result = document.execCommand('copy');
}
catch(err){
result = false;
}
finally{
document.body.removeChild(v);
}
if(result === true){
spUtil.addInfoMessage("Text copied to clipboard");
}
else{
$window.prompt("${Because of a browser limitation the URL can not be placed directly in the clipboard. Please use Ctrl-C to copy the data and escape to dismiss this dialog}", permalink);
}
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:25 AM