0

How to stop takeing Screenshot in react without using api in React Js

In java script how to stop taking Screen Short

30th Dec 2022, 1:29 PM
Supercool Coder
Supercool Coder - avatar
3 Respostas
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;
31st Dec 2022, 4:19 AM
Calviղ
Calviղ - avatar
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"; } });
31st Dec 2022, 4:23 AM
Calviղ
Calviղ - avatar
0
Thanks brother
31st Dec 2022, 4:37 AM
Supercool Coder
Supercool Coder - avatar