Using this we can control user interactions with sensitive content - In service portal widget

Sai Kiran4
Tera Contributor

Hi #ServiceNow #Community .
In this example, I have implemented functionality to prevent text in a specific text area from being copied, cut, pasted, or captured via screenshot.

ng-paste, ng-copy, ng-cut, and ng-keydown : - These directives are bound to a single function, refuseInvalid($event), which captures user attempts to copy, cut, or paste in the text area. The function uses event.preventDefault() to block these actions effectively.
To deter screenshots, the jQuery function listens for the "Print Screen" key (key code 44). When detected, it clears the content of the text area immediately.

#code
HTML :
<div>
<p id="ai_question">Text Box which doesn’t allow copy, cut, paste, or screenshots</p>
<textarea id="ai-comments" class="form-control scrollable-textarea"
ng-keydown="refuseInvalid($event)" ng-paste="refuseInvalid($event)"
ng-copy="refuseInvalid($event)" ng-cut="refuseInvalid($event)">
Hi Everyone, Capture me if you can!
</textarea>
</div>

CLIENT SCRIPT :
api.controller = function($scope) {
/* Widget controller */
var c = this;
$(window).keyup(function(e) {
if (e.keyCode == 44) { // Check if the Print Screen key is pressed
$('#ai-comments').val('');
}
}); // ends here Jquery

$scope.refuseInvalid = function(event) {
if (event.type === 'paste') {
event.preventDefault();
return false;
}
if (event.type === 'copy') {
event.preventDefault();
return false;
}
if (event.type === 'cut') {
event.preventDefault();
return false;
}
};
};

"Using this we can control user interactions with sensitive content"
#ServiceNow

0 REPLIES 0