0
How to stop takeing Screenshot in react without using api in React Js
In java script how to stop taking Screen Short
3 Réponses
0
To take a screenshot of the current component, running
npm install html2canvas
in your project's directory
with this react.js code
import React from 'react';
import html2canvas from 'html2canvas';
const MyComponent = () => {
const takeScreenshot = () => {
const element = document.querySelector('#my-component');
html2canvas(element).then((canvas) => {
document.body.appendChild(canvas);
});
}
return (
<div>
<div id="my-component">This is my component</div>
<button onClick={takeScreenshot}>Take Screenshot</button>
</div>
);
}
export default MyComponent;
0
Here is an example of how you can use JavaScript to detect when a user takes a screenshot and display a warning message:
document.addEventListener("keydown", function(event) {
if (event.ctrlKey && event.key === "s") {
alert("Screenshot detected! Please do not take screenshots of this page.");
}
});
The following code is to redirect the user to a different page instead of displaying a warning message:
document.addEventListener("keydown", function(event) {
if (event.ctrlKey && event.key === "s") {
window.location.href = "http://www.example.com";
}
});
0
Thanks brother