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 completely 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.
It is not possible 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 serverside, and only send the client the information they need to know/requested.
There are some free javascript obfuscators, such as https://javascriptobfuscator.com/. 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.com
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 combination 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.com/contact-facebook-directly/6579/
Edit:
all input from keyboard is disabled, but by adding "view-source:" before the httpps:// to the url to become:
view-source:https://www.techgyd.com/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
I have this function tied to an onclick event of a button. It should check to see if the documentElement it should toggle full screen mode and swap the button image.
function toggleFS() {
var fsmode = (document.fullScreenElement && document.fullScreenElement !== null) || // alternative standard method
(document.mozFullScreen || document.webkitIsFullScreen);
var page = document.documentElement;
if(!fsmode) {
if(page.requestFullscreen) {
page.requestFullscreen();
} else if (page.mozRequestFullScreen) {
page.mozRequestFullScreen();
} else if (page.webkitRequestFullScreen) {
page.webkitRequestFullScreen();
}
document.getElementById("toggle-fs").innerHTML = '<img src="/images/nofs.png">';
} else {
if (page.exitFullscreen) {
page.exitFullscreen();
} else if (page.msExitFullscreen) {
page.msExitFullscreen();
} else if (page.mozCancelFullScreen) {
page.mozCancelFullScreen();
} else if (page.webkitExitFullscreen) {
page.webkitExitFullscreen();
}
document.getElementById("toggle-fs").innerHTML = '<img src="/images/fs.png">';
}
}
On the first click after page load, it works correctly and puts the page in fullscreen and switches the button to the exit fullscreen image.
On the second click, it replaces the image for the button but does not exit fullscreen. (Hitting 'ESC' still works.)
Any following clicks do nothing at all. So it is stuck in fullscreen with the go to fullscreen button.
This behavior is in Chrome 56.
Can anyone see where I've gone wrong here?
The functions to request full screen, such as webkitRequestFullScreen, are on document.documentElement, but the ones to exit full screen, such as webkitExitFullscreen, are just on document. The snippet below works properly on Chrome, Edge, and IE.
document.getElementById("toggle-fs").addEventListener("click", function() {
toggleFS()
});
function isFullScreen() {
return (document.fullScreenElement && document.fullScreenElement !== null) ||
(document.msFullscreenElement && document.msFullscreenElement !== null) ||
(document.mozFullScreen || document.webkitIsFullScreen);
}
function enterFS() {
var page = document.documentElement
if (page.requestFullscreen) page.requestFullscreen();
else if (page.mozRequestFullScreen) page.mozRequestFullScreen();
else if (page.msRequestFullscreen) page.msRequestFullscreen();
else if (page.webkitRequestFullScreen) page.webkitRequestFullScreen();
}
function exitFS() {
if (document.exitFullScreen) return document.exitFullScreen();
else if (document.webkitExitFullscreen) return document.webkitExitFullscreen();
else if (document.msExitFullscreen) return document.msExitFullscreen();
else if (document.mozCancelFullScreen) return document.mozCancelFullScreen();
}
function toggleFS() {
if (!isFullScreen()) {
enterFS();
document.getElementById("toggle-fs").innerHTML = '<img src="/images/nofs.png">';
} else {
exitFS();
document.getElementById("toggle-fs").innerHTML = '<img src="/images/fs.png">';
}
}
JsFiddle
Try this one
<button id="toggle-fs" onclick="toggleFullScreen()"><img src="/images/nofs.png"></button>
with...
document.getElementById("toggle-fs").style.display = "block";
Good luck!
I'm working on a webapp that will be used on iOS devices as well as Desktops (without touch).
We are using a bootstrap to make the site as responsive as possible.
We want to incoperate the spinning wheel known in iOS.
We will style it differently but not the functionality.
After some searching I came across this site:
http://cubiq.org/spinning-wheel
However this script only seems to work on touch capable devices. Would it be possible to edit the script so it will work on desktops too?
I found this in the script can I add a mouseClickHandler here?
handleEvent: function (e) {
console.log(e.type);
if (e.type == 'touchstart') {
this.lockScreen(e);
if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') {
this.tapDown(e);
} else if (e.currentTarget.id == 'sw-frame') {
this.scrollStart(e);
}
} else if (e.type == 'touchmove') {
this.lockScreen(e);
if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') {
this.tapCancel(e);
} else if (e.currentTarget.id == 'sw-frame') {
this.scrollMove(e);
}
} else if (e.type == 'touchend') {
if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') {
this.tapUp(e);
} else if (e.currentTarget.id == 'sw-frame') {
this.scrollEnd(e);
}
} else if (e.type == 'webkitTransitionEnd') {
if (e.target.id == 'sw-wrapper') {
this.destroy();
} else {
this.backWithinBoundaries(e);
}
} else if (e.type == 'orientationchange') {
this.onOrientationChange(e);
} else if (e.type == 'scroll') {
this.onScroll(e);
}
},
You could try using drag events, but they aren't supported well. Check out this MDN article and this one with more explanation on the events. You could also try using jQuery with for instance this plugin. Good luck!
I have been coding a couple of shortcuts for my web application, one of them saves the page i am working on, the other closes the page.
Both of these shortcuts work as do the functions themselves.
Both of these shortcuts are for webAdmins so that they can save and close our theme editing pages quickly. COMMAND+S saves the page and closes, whereas ESC just closes the page.
The issue is that when I press COMMAND+F to search for something it searches no problem, but if i press the "S" key afterwards or anytime during my search it acts as though i press COMMAND+S and saves and closes the page, as though it hit the shortcut, even though COMMAND+S are not being pressed at the same time.
Does anyone know how to explain this behavior? I have tried everything.
Here is my code:
enableHotkeys: function() {
var isCommand = false;
document.onkeyup=function(e) {
if (e.which == 91) {
isCommand=false;
}
};
document.onkeydown=function(e) {
if (e.which == 91) {
isCommand = true;
} else if (e.which == 83 && isCommand == true) {
themeArchive.codeEditSave();
return false;
} else if (e.which == 27) {
themeEditPanel.close();
return false;
}
};
},
disableHotkeys: function() {
document.onkeyup=function(e) {};
document.onkeydown=function(e) {};
},
I have this script:
window.onload = function(){
document.getElementById('workspace').oncontextmenu = function(){
return false;
}
}
function click(e) {
if (navigator.appName == 'Netscape' && e.which == 3) {
window.location.reload();
return false;
else {
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)
window.location.reload();
return false;
}
return true;
}
document.onmousedown=click;
The workspace is id of my <body> element. Basically this script does is, it reloads the current page when right clicked on the page. I'm happy with it, this is all I want.
But this script is having a bug. The problem is the left click is disabled. I have some text on webpage but the you can select the text with this script enabled.
I have no much experience with JavaScript but I tried removing the last line of the script. When I did so the left click started working and I can select the text, but soon I noted that reload does not works.
It could be because of click function return false in the third line.
you need } before else { and need to wrap with { } for last if block.
something like this should be ok.
function click(e) {
if (navigator.appName == 'Netscape' && e.which == 3) {
window.location.reload()
return false;
} else {
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
window.location.reload();
return false;
}
}
return true;
}