'Disable Copy, Cut, Paste and Right Click for PDF inside iframe [duplicate]
I can't disable Copy, Cut, Paste and Right Click actions for PDF inside iframe
my code for the iframe
<iframe id="pdfViewer" src="url-pdf.pdf#toolbar=0&navpanes=0&scrollbar=0" title="Title PDF" frameborder="0" scrolling="auto" class="no-right-click no-cut-copy-paste" height="400px" width="100%" style="border: 30px solid #EEE"></iframe>
I've tried many solutions, but no one is work for me
Some solution I've tried using
1. css:
.no-cut-copy-paste {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
2. Javascript
var pdfViewer = document.getElementById('pdfViewer');
pdfViewer.window.eval('document.addEventListener("contextmenu", function (e) {e.preventDefault();}, false)');
$(document).on('cut copy paste', '.no-cut-copy-paste', function(e) {
e.preventDefault();
return false;
});
3. jQuery
$('#pdfViewer').attr('contextmenu', 'return false')
But there is work for all pages of my application, but the right click is still active on iframe
document.oncontextmenu = function() {
return false;
};
Solution 1:[1]
<html>
<head>
<title>Disable Context Menu</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script type="text/jscript">
function injectJS(){
var frame = $('iframe');
var contents = frame.contents();
var body = contents.find('body').attr("oncontextmenu", "return false");
var body = contents.find('body').append('<div>New Div</div>');
}
</script>
</head>
<body >
<iframe id="myiframe" width="528" height="473" onload="injectJS()"
></iframe>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | virender ditro |
