How do you disable/ view source/ and /inspect element/, ctrl + u ctrl+shift+I f12 menu bar and right click, also ctrl + s ctrl p ctrl+v ctrl+a ctrl+c and drag select page, please answer all parts that's possible, I prefer to do this will JavaScript array keycodes or html no php or other languages.also I want to block ifram use on my site like somesites such as google. As I understand it is not possible to pletely disable view source and inspect element, so I want minification of code and rest of my question answered instead.
Edit:
I solved alot of it myself, I used onkeydown return false to disable all keys, still need the arrays, I disabled inspect element menu bar by forcing browser to window.open
I still need right click, however would like to add that I need a custom right click menu, I disabled the possibility to disable Javascript in order to stop the key block by using noscript function redirects. I also still need the drag and select part. I would still like betterways to fix it...maybe even just minify the code or encrypt it. Of anyone needs some of the code I used just reply. I just need to fix it.
How do you disable/ view source/ and /inspect element/, ctrl + u ctrl+shift+I f12 menu bar and right click, also ctrl + s ctrl p ctrl+v ctrl+a ctrl+c and drag select page, please answer all parts that's possible, I prefer to do this will JavaScript array keycodes or html no php or other languages.also I want to block ifram use on my site like somesites such as google. As I understand it is not possible to pletely disable view source and inspect element, so I want minification of code and rest of my question answered instead.
Edit:
I solved alot of it myself, I used onkeydown return false to disable all keys, still need the arrays, I disabled inspect element menu bar by forcing browser to window.open
I still need right click, however would like to add that I need a custom right click menu, I disabled the possibility to disable Javascript in order to stop the key block by using noscript function redirects. I also still need the drag and select part. I would still like betterways to fix it...maybe even just minify the code or encrypt it. Of anyone needs some of the code I used just reply. I just need to fix it.
- 4 What is your goal for this? Are you trying to prevent the user from seeing something hidden in your HTML? Keep in mind that no matter what client-side restrictions you put on the user, you're still handing their browser the entire page which they can pick apart with other methods. – Eric Dobbs Commented Jun 1, 2017 at 14:59
- 1 Yes, I am attempting to block something In the source, however I found one not very reliable method i need a better one. – Universal Omega Commented Jun 1, 2017 at 15:03
- 8 It's simply not possible, any user will be able to see your code no matter what you do. Whatever the browser can see, the user can see too. Anything secret needs to be kept on the server. – Lennholm Commented Jun 1, 2017 at 15:06
- 1 What about encryption of the code or minifying it? – Universal Omega Commented Jun 1, 2017 at 15:09
- 4 If you minify it, it will be harder to read for sure but everything will still be there. Encryption is pointless since you would have to decrypt it in the browser in order to make the code run. – Lennholm Commented Jun 1, 2017 at 15:12
6 Answers
Reset to default 3It is impossible to prevent the user from inspecting code running on their machine. At the end of the day, the HTML they are getting delivered will be readable in plain text. You can cause a nuisance for most people, but this will not be a valid security measure - chrome extensions will still run, for instance, so if someone is using the NoScript extension it will disable all javascript.
A much better option would be to handle your logic server side, and only send the client the information they need to know/requested.
There are some free javascript obfuscators, such as https://javascriptobfuscator./. Please remember that it is not a secure method, though.
I mean no matter how much you block it a person can just type
view-source:https://example.
document.onkeydown = function(e)
{
if(event.keyCode == 123)
{
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0))
{
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0))
{
return false;
}
if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0))
{
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0))
{
return false;
}
}
e is a keyboard event. e.[key] returnes true if key pressed.
If document.onkeydown returns false, key doesn't count.
This programm seeing if code view bination pressed and returning false.
Example. if ctrl, shift and 'J' pressed - return false.
Bump
To the people saying it isn't possible, how would you recon this website managed to do so?
The following website disabled, view source, right click and the dev console.
I am genuinely interested.
https://www.techgyd./contact-facebook-directly/6579/
Edit: all input from keyboard is disabled, but by adding "view-source:" before the httpps:// to the url to bee:
view-source:https://www.techgyd./contact-facebook-directly/6579/
makes me able to see.
If you would like to know how they did that then take a look at their JS, raw copy/paste:
<script type="text/javascript">
//<![CDATA[
var show_msg = '';
if (show_msg !== '0') {
var options = {view_src: "View Source is disabled!", inspect_elem: "Inspect Element is disabled!", right_click: "Right click is disabled!", copy_cut_paste_content: "Cut/Copy/Paste is disabled!", image_drop: "Image Drag-n-Drop is disabled!" }
} else {
var options = '';
}
function nocontextmenu(e) { return false; }
document.oncontextmenu = nocontextmenu;
document.ondragstart = function() { return false;}
document.onmousedown = function (event) {
event = (event || window.event);
if (event.keyCode === 123) {
if (show_msg !== '0') {show_toast('inspect_elem');}
return false;
}
}
document.onkeydown = function (event) {
event = (event || window.event);
//alert(event.keyCode); return false;
if (event.keyCode === 123 ||
event.ctrlKey && event.shiftKey && event.keyCode === 73 ||
event.ctrlKey && event.shiftKey && event.keyCode === 75) {
if (show_msg !== '0') {show_toast('inspect_elem');}
return false;
}
if (event.ctrlKey && event.keyCode === 85) {
if (show_msg !== '0') {show_toast('view_src');}
return false;
}
}
function addMultiEventListener(element, eventNames, listener) {
var events = eventNames.split(' ');
for (var i = 0, iLen = events.length; i < iLen; i++) {
element.addEventListener(events[i], function (e) {
e.preventDefault();
if (show_msg !== '0') {
show_toast(listener);
}
});
}
}
addMultiEventListener(document, 'contextmenu', 'right_click');
addMultiEventListener(document, 'cut copy paste print', 'copy_cut_paste_content');
addMultiEventListener(document, 'drag drop', 'image_drop');
function show_toast(text) {
var x = document.getElementById("amm_drcfw_toast_msg");
x.innerHTML = eval('options.' + text);
x.className = "show";
setTimeout(function () {
x.className = x.className.replace("show", "")
}, 3000);
}
//]]>
</script>
or just look from line 86 I hope it helps
<script type="text/javascript">
// Disable right-click
document.addEventListener("contextmenu", function(event) {
event.preventDefault();
show_toast("Right-click is disabled.");
});
// Disable specific keyboard shortcuts
document.addEventListener("keydown", function(event) {
// F12
if (event.keyCode === 123) {
event.preventDefault();
show_toast("Inspect Element is disabled.");
}
// Ctrl+Shift+I (Inspect Element), Ctrl+Shift+J (Console), Ctrl+U (View Source)
if ((event.ctrlKey && event.shiftKey && (event.keyCode === 73 || event.keyCode === 74)) ||
(event.ctrlKey && event.keyCode === 85)) {
event.preventDefault();
show_toast("Developer tools access is disabled.");
}
// Ctrl+S (Save), Ctrl+P (Print), Ctrl+C (Copy), Ctrl+V (Paste), Ctrl+A (Select All)
if ((event.ctrlKey && (event.keyCode === 83 || event.keyCode === 80 ||
event.keyCode === 67 || event.keyCode === 86 ||
event.keyCode === 65))) {
event.preventDefault();
show_toast("This action is disabled.");
}
});
// Disable text selection
document.addEventListener("selectstart", function(event) {
event.preventDefault();
show_toast("Text selection is disabled.");
});
// Disable drag
document.addEventListener("dragstart", function(event) {
event.preventDefault();
show_toast("Dragging is disabled.");
});
// Disable cut, copy, and paste actions
document.addEventListener("copy", function(event) {
event.preventDefault();
show_toast("Copy is disabled.");
});
document.addEventListener("cut", function(event) {
event.preventDefault();
show_toast("Cut is disabled.");
});
document.addEventListener("paste", function(event) {
event.preventDefault();
show_toast("Paste is disabled.");
});
// Function to show a toastDisable message
function show_toast(message) {
// Create a toastDisable element if it doesn't exist
if (!document.getElementById("toastDisable")) {
const toast = document.createElement("div");
toast.id = "toastDisable";
toast.className = "toastDisable";
document.body.appendChild(toast);
}
// Display the message in the toastDisable
const toast = document.getElementById("toastDisable");
toast.innerText = message;
toast.classList.add("show");
// Remove the message after 3 seconds
setTimeout(function() {
toast.classList.remove("show");
}, 3000);
}
setInterval(function() {
// Check if the developer tools are opened by paring outer and inner dimensions
if (window.outerWidth - window.innerWidth > 100 || window.outerHeight - window.innerHeight > 100) {
alert("Developer tools are opened. Please close them to continue.");
window.location.href = '/'; // Redirect to the homepage or desired URL
}
}, 1000);
</script>
<!-- Add this CSS inside a <style> tag or in your stylesheet -->
<style>
/* Toast notification styling */
.toastDisable {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #333;
color: #fff;
padding: 10px;
border-radius: 5px;
z-index: 1000;
font-size: 14px;
display: none;
opacity: 0;
transition: opacity 0.5s ease;
}
.toastDisable.show {
display: block;
opacity: 1;
}
</style>
Probably you can use this!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Partial closed source</title>
</head>
<body>
<h1>Partial closed source</h1>
<script>
// Disable key binations for opening developer tools and saving the page
document.onkeydown = function(e) {
if (e.keyCode === 123 || // F12
(e.ctrlKey && e.shiftKey && ['I', 'J', 'C', 'E'].includes(String.fromCharCode(e.keyCode))) ||
(e.ctrlKey && e.keyCode === 'U'.charCodeAt(0)) || // Ctrl+U
(e.ctrlKey && e.keyCode === 'S'.charCodeAt(0)) // Ctrl+S
) {
e.preventDefault();
return false;
}
};
// Disable right-click menu
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
});
</script>
</body>
</html>