Just giving the community a poke, is it possible to prevent right-clicking on wikidot sites? Or perhaps on specific pages?
Omnia mutantur, nihil interit.
Just giving the community a poke, is it possible to prevent right-clicking on wikidot sites? Or perhaps on specific pages?
Omnia mutantur, nihil interit.
It can be done by wrapping the content in a HTML block and adding some javascript. I found some code and just gave it a whirl. It does work, but might not be a great solution depending on how you want to use it (I'm guessing you want to try and protect images).
I've always thought is wasn't that useful since it's so easy to take a screenshot if you really want to get around those types of blocks.
Here's the code I found and it also disables some keystrokes to prevent poking around with the developer tools and saving a page. Here's the code I got working. You should be able to paste it into a page on your site to see it in action.
[[html]]
<h1>Disable Right-Click Demo</h1>
<p>Place your images in a HTML block and add the javascript below to disable right-click and other keys.</p>
<img src="http://community.wdfiles.com/local--resized-images/files/cerezos_20b.jpg/medium.jpg" alt="Demo for Naomi"/>
<hr>
<script language="JavaScript">
/**
* Disable right-click of mouse, F12 key, and save key combinations on page
* By Arthur Gareginyan (arthurgareginyan@gmail.com)
* For full source code, visit http://www.mycyberuniverse.com
*/
window.onload = function() {
document.addEventListener("contextmenu", function(e){
e.preventDefault();
}, false);
document.addEventListener("keydown", function(e) {
//document.onkeydown = function(e) {
// "I" key
if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
disabledEvent(e);
}
// "J" key
if (e.ctrlKey && e.shiftKey && e.keyCode == 74) {
disabledEvent(e);
}
// "S" key + macOS
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
disabledEvent(e);
}
// "U" key
if (e.ctrlKey && e.keyCode == 85) {
disabledEvent(e);
}
// "F12" key
if (event.keyCode == 123) {
disabledEvent(e);
}
}, false);
function disabledEvent(e){
if (e.stopPropagation){
e.stopPropagation();
} else if (window.event){
window.event.cancelBubble = true;
}
e.preventDefault();
return false;
}
};
</script>
[[/html]]
As always you rock, def going to plug this in and check it out. Thank you!
Omnia mutantur, nihil interit.