rejetto forum

Disable Right Click in template

d95gas · 8 · 8125

0 Members and 1 Guest are viewing this topic.

Offline d95gas

  • Occasional poster
  • *
    • Posts: 10
    • View Profile
Hi All,

Been a while since I have been on, and some fantastic work been done in the that time.

I am hoping someone can point me in the right direction.   I want to be able to disable RIGHT mouse click when the web page for HFS is running, to prevent the users from doing anything than clicking on the file to open/download.

Hoping someone might have an answer.


Thanks


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
hi,
you will find the code you need somewhere on google, then
1. ensure it is enclosed within <script> tags
2. go to hfs, in the "virtual file system" box, right clik on the first element (HOME)
3. properties
4. diff template
5. enter this text:
Code: [Select]
[+]
<script>
insert your code here
</script>


Offline d95gas

  • Occasional poster
  • *
    • Posts: 10
    • View Profile
Thanks for the quick reply.

I followed your instructions to the letter posting the code as indicated below.   When I open the site (localhost) it will open the page without anything showing on the page other than the header.

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;   
   }
}
</script>



I am obviously missing the point somewhere :-(


Thanks


Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 910
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
http://stackoverflow.com/questions/737022/how-do-i-disable-right-click-on-my-web-page

html code it:

<script language="javascript">

document.addEventListener("contextmenu", function(e){
    e.preventDefault();
}, false);
}
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;   
   }
}
</script>

Jquery will work better with HFS

<script language="javascript">
// With jQuery
$(document).on({
    "contextmenu": function(e) {
        console.log("ctx menu button:", e.which);

        // Stop the context menu
        e.preventDefault();
    },
    "mousedown": function(e) {
        console.log("normal mouse down:", e.which);
    },
    "mouseup": function(e) {
        console.log("normal mouse up:", e.which);
    }
});
</script>
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing


Offline d95gas

  • Occasional poster
  • *
    • Posts: 10
    • View Profile
Tried that and all I get when I load up a page is "Jquery will work better with HFS "


Thanks anyway




Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 910
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
that base info, that not a complete code... see the web link provided with info regarding these two codes, that are still ways to "stop this".....

but here is a working html code, you can drop into the different template tab

Code: [Select]
<head>

<script language="javascript">
// With jQuery
$(document).on({
    "contextmenu": function(e) {
        console.log("ctx menu button:", e.which);

        // Stop the context menu
        e.preventDefault();
    },
    "mousedown": function(e) {
        console.log("normal mouse down:", e.which);
    },
    "mouseup": function(e) {
        console.log("normal mouse up:", e.which);
    }
});
</script>

<script language="javascript">
document.addEventListener("contextmenu", function(e){
    e.preventDefault();
}, false);
</script>

</head>

<body>
<p> test, you can't mousr click </p>
</body
« Last Edit: April 11, 2016, 02:42:36 PM by bmartino1 »
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
sorry for the long wait, d95gas.
my advice was correct, but a bug in HFS prevented it from working.
It will work in HFS 2.3h

After fixing i tried your code, and found a typo: "Function" must be all lowercase.