Author Topic: Disable Right Click in template  (Read 2187 times)

0 Members and 1 Guest are viewing this topic.

Offline d95gas

  • Occasional poster
  • *
  • Posts: 10
    • View Profile
Disable Right Click in template
« on: April 06, 2016, 05:58:56 PM »
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: 12890
    • View Profile
Re: Disable Right Click in template
« Reply #1 on: April 07, 2016, 11:58:02 AM »
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
Re: Disable Right Click in template
« Reply #2 on: April 07, 2016, 02:08:19 PM »
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

Follow members gave a thank to your post:


Offline bmartino1

  • Tireless poster
  • ****
  • Posts: 788
  • I'm only trying to help i mean no offense.
    • View Profile
    • none - google translate
Re: Disable Right Click in template
« Reply #3 on: April 08, 2016, 01:16:51 AM »
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>
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Offline d95gas

  • Occasional poster
  • *
  • Posts: 10
    • View Profile
Re: Disable Right Click in template
« Reply #4 on: April 08, 2016, 04:44:48 AM »
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: 788
  • I'm only trying to help i mean no offense.
    • View Profile
    • none - google translate
Re: Disable Right Click in template
« Reply #5 on: April 11, 2016, 03:09:07 AM »
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 »
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12890
    • View Profile
Re: Disable Right Click in template
« Reply #6 on: April 24, 2016, 10:21:36 AM »
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.

Follow members gave a thank to your post:


Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12890
    • View Profile