Hi,
I tried to place this code in WIX code but it did not work could someone tell me why ?
Hi,
I tried to place this code in WIX code but it did not work could someone tell me why ?
WixCode understands all of Javascript, except for anything that accesses the DOM.
This keeps the user from inadvertently âbreakingâ something. I myself tried to hack things from the code, from an iFrame, and in my dreams, but WixCode wasnât having any of it.
Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w.
One small exception is the $w.HtmlComponent (which is based on an iFrame). This element was designed to contain vanilla HTML and it works just fine. You just canât try to trick it by using parent, window, top, etc. Same goes with the Javascript evaluate() function. It is sandboxed and does not allow access to the DOM.
You tried to disable the right click on the WHOLE website, or on images? (To protect them from being right-click and ââSaved asââ ?
If so, wix have a thing called ââRight click protectââ (if you donât want any copyright text, just set the opacity at 0%)
It do not work inside repeaters, but⌠a simple square with 0% opacity on top of your image do the same work!
If the code is suppose to disable the right click inside the whole website, than i cannot help you with that sorry !
Try using the javascript given below. Go to Dashboard>Tracking tool>Add Custom code . Paste the java script in the Body Start.
This will disable right click everywhere in your website, and will protect your content and download. This perfectly works for me.
<!- start disable copy paste --><script src='demo-to-prevent-copy-paste-on-blogger_files/googleapis.js'></script><script type='text/javascript'> if(typeof document.onselectstart!="undefined" ) {document.onselectstart=new Function ("return false" ); } else{document.onmousedown=new Function ("return false" );document.onmouseup=new Function ("return false"); } </script>
<!-- End disable copy paste --></!->
<script language=javascript>
<!--
//edit by iamravlo
var message="Right Click Has Been Disabled";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
// -->
</script>
It worked perfectly for me as well (all pages). Thank you so much Vivek for this top tip.
Here is a code I created to disable right-clicking for the images, on my end is working for desktop and mobile. Feel free to use it!
<script>document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('img').forEach(function(img) {
img.addEventListener('contextmenu', function(e) {
e.preventDefault();
});
});
});
</script>
worked for desktop version. thanks a lot.
what about mobile version?