CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Blocking browser context menu  (Read 608 times)

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Blocking browser context menu
« on: 27 Aug 2023, 09:47:43 pm »
So far i have found 3 ways to block the context menu of the browser.

with a div id prevent around the page content

first we disable the right click
then we disable the shift - F10 which is the windows shortcut
then we disable the shift - right click

so far it works great on chrome, but firefox shift - f10 forces the menu (its a known challenge)

Code: [Select]

  /*  right click */
 
              document.getElementById('prevent').oncontextmenu = function ()
              {
                alert('Menu Disabled Sorry!');
                return false;
              };
             
             
             
              /* shift F10  */
              document.body.addEventListener('keydown',function(ev){
              if (ev.keyCode === 121 && ev.shiftKey === true)
                       {
                           
                         ev.preventDefault();
                         alert('Menu Disabled Sorry!');
                         return false;
                       }
              });
             
             
             
              /* shift right click */
              document.body.addEventListener('mousedown',function(evt){
                  if (evt.which === 3 && evt.shiftKey === true)
                  {
                    evt.preventDefault();
                    alert('Menu Disabled Sorry!');
                    return false;
                   }
             });
             
                 


too bad  i cant stop the firefox force issue, but i think that pretty much covers it for most situations.  If they try right click and get the message, they might try one other way, (i did not know there were 3 ways till tonight) .....     i just dont want any looky - looos   

« Last Edit: 27 Aug 2023, 09:57:13 pm by durangod »

benanamen

  • Full Member
  • ***
  • Posts: 187
  • Karma: +18/-0
Re: Blocking browser context menu
« Reply #1 on: 28 Aug 2023, 01:27:03 am »
All have to do is turn off JavaScript in my browser. I can also just make an HTTP request to view the page source. You are not stopping anything.
To save time, let's just assume I am never wrong.

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #2 on: 28 Aug 2023, 01:29:23 pm »
but nothing works without js, it has to be enabled for pages to load.

as to the http request, i was not aware of that, can you give example please.  is it a special req?

Are you talking about something like:

Code: [Select]
GET /thepage.html HTTP/1.1
Host: www.example.com


You know my test site url, its set up there to block.  Use chrome and tell me if you can see the source on the test site.  :)
« Last Edit: 28 Aug 2023, 03:23:39 pm by durangod »

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #3 on: 28 Aug 2023, 04:38:57 pm »
Here are other ways, on firefox go to menu -> more tools and there is an option there for :

browser console : cntrl -> shift + j
page source: contrl + u
web developer tools   cntrl +> shift + i

and

view-source:https://example.com/index.php


ill try to block those too :)

Just FYI this will be an option for the site admin to turn on or off.   Everything but the view-source prefix block as that will need to be done via htaccess.   But they can comment out the code if they wish to disable that too.
« Last Edit: 28 Aug 2023, 05:34:35 pm by durangod »

coothead

  • Sr. Member
  • ****
  • Posts: 380
  • Karma: +89/-0
  • I smile benignly
    • coothead's stuff ~ an eclectic collection
Re: Blocking browser context menu
« Reply #4 on: 28 Aug 2023, 05:43:44 pm »
browser console : cntrl -> shift + j
page source: contrl + u
web developer tools   cntrl +> shift + i

view-source:https://example.com/index.php
I'll try to block those too :)

Haven't you got anything better to do ? 

Look at it this way: those who actually have a desire to view
your source code will most certainly have the wherewithal
to overcome your feeble effects at preventing them.   

Those who do not have that  desire will,  obviously,  never
need your continuing blocking attempts will they ?   

coothead
~ the original bald headed old fart ~

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #5 on: 28 Aug 2023, 06:19:00 pm »
Hi,

Yes i do have better things to do, but remember i am learning, and i have been working hard and every now and then i need a day to work on easy things, things that dont take all my brain power.   I thought this would be an easy thing.   Whip up a config value, assign it, add the code to the html form, and the save process and boom done.   

So what i learned is that you cant block view-source protocol, at least not with htaccess.  The reason being that its userside browser related not server related. .   

My htaccess attempt was:

Code: [Select]
RewriteCond %{QUERY_STRING} ^view-source$
RewriteRule - [F]

PS coothead, i am trying new things to learn.  I could just use crappy code and crap i pull from the web and never ask any questions at all.   I am trying to do this correctly and i deserve sometimes to try new stuff to learn and ask along the way.   
« Last Edit: 29 Aug 2023, 04:19:55 pm by durangod »

coothead

  • Sr. Member
  • ****
  • Posts: 380
  • Karma: +89/-0
  • I smile benignly
    • coothead's stuff ~ an eclectic collection
Re: Blocking browser context menu
« Reply #6 on: 28 Aug 2023, 06:47:22 pm »
I really dont need your help or your negative comments coothead.

I am very sorry that I have upset you, that certainly was never my intention.

I thought that all attempts at context menu blocking had long since been
put to bed.

I wiil accept that my use of feeble in personal way was rather unkind.

I really should have applied it impersonally to the attempts...

"All attempts at context menu blocking are feeble and  have long since been
put to bed.
"

I apologise for upsetting you so with  my clumsiness.

coothead
~ the original bald headed old fart ~

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #7 on: 28 Aug 2023, 08:25:43 pm »
All is good, i apologize as well, i should not have taken it that way.   

Anyway the way i see things its about learning.  Even if whatever i am doing is useless, if i can learn something from it then its not wasted.    I am well aware that everything i do no matter what and no matter what its regarding, the basic rule of anything and everything online is.  if they want it they will get it.     But it does not hurt to try different things.   

I actually thought i would get replies like, hey you can put that in one statement, or have you ever seen this or that..  Stuff like that....      Who knows when i might have to block a key combo sometime, and now i atleast know how to do it alittle bit.   So i learned several things by doing this, time not wasted ya know...

Again sorry i took it so harshy, i should know better.    I guess maybe one reason i am so cranky about it all is that every day people tell me im wasting my time with this project, that i am a outdated relic in a new AI world.  That this project is going to be a big flop and i should just delete it all.   Then they tell me that they dont like the way i do this, or that.  There is too much documentation, too many things to read on the pages,  that my themes suck, or this sucks, or they hate the skinny input fields for login.     I get negatives every day from testers and people i thought would never be so petty as to complain about the things they complain about.     

So when you said "dont you have better things to do"  it just hit a nerve is all.....    I am not upset anymore, i know you did not mean it that way.  Like i said i should have known better.

peace man.... :)

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +8/-0
    • Grumpy Young Man
Re: Blocking browser context menu
« Reply #8 on: 29 Aug 2023, 03:46:35 am »
PS coothead, why so negative at someone that is trying new things to learn.  I could just use crappy code and crap i pull from the web and never ask any questions at all.   I am trying to do this correctly and i deserve sometimes to try new stuff to learn and ask along the way.    Dont you have anything better to do than to be snotty, if you dont have anything nice to say, dont say anything at all, how about that.....   I really dont need your help or your negative comments coothead.
Oh my, please don’t catch Jason on a bad day then... Coothead is a pussy cat in comparison...
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #9 on: 29 Aug 2023, 09:19:23 am »
here are ways via chrome, i have not yet tried it but it looks like it would work.

Code: [Select]
If you want to block an URL whose subdomain contains some keyword, you need to match the whole domain, and use JavaScript to check whether the subdomain contains the profane word.

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
        var hostname = details.url.split('/', 3)[2];
        return {
            cancel: hostname.indexOf('badword') >= 0
        };
    },
    {
        urls:["*://*.example.com/*"]
    },
    ["blocking"]
);


Code: [Select]
Or using the chrome.declarativeWebRequest API (omitted chrome.runtime.onInstalled event for brevity):

chrome.declarativeWebRequest.onRequest.addRules({
    id: 'some rule id',
    conditions: [
        new chrome.declarativeWebRequest.RequestMatcher({
            url: {
                hostContains: 'badword',
                hostSuffix: '.example.com'
            }
        })
    ],
    actions: [
        new chrome.declarativeWebRequest.CancelRequest()
    ]
});


source:  stackoverflow.com/questions/19956976/block-url-with-a-specific-word-somewhere-in-the-subdomain
« Last Edit: 29 Aug 2023, 09:45:36 am by durangod »

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #10 on: 29 Aug 2023, 10:07:52 am »
Oh my, please don’t catch Jason on a bad day then... Coothead is a pussy cat in comparison...

@GrumpyYoungMan   yes i know DS can be grainy at times.  But in all the many years i have known him online he has never attacked me. I am not saying that coothead did (i took what he said 100% wrong). I am just saying that DS has never done so.  DS usually says one of the follow in most cases:

1. There is no reason to do that and explains why
2. Ok if your going to go down this road till you fall off a cliff, then atleast code it correctly, and shows example.
3. Why are you hacking that code to pieces like that, that is not the right way to do that, i would do it this way.
4.  Variables for nothing and the use of rediculous tick marks around field names drives me crazy...
5. That is not "fill in the blanks" job, that is "fill in the blank" job.
6. What!  Are we still living in 2004 and using php 4 

DS may be like sandpaper sometimes be he is always about the code.   When i first saw his posts on the old coding forum i was alittle shocked because i was not used to those kinds of replies on a coding forum environment.  Back then he went by a different name, off hand i dont remember, but i think i know which one looking at the userlist.   But anyway as the years went by he got alittle bit more like 20 grit sandpaper than 120 grit of years past.   But it was always about the same thing.  Code, code structure, whos job it is for different tasks.  Even though some of those views may have changed over the years, he still talks about the code.   Even when he says "doing it that way is idiotic"  he is not calling the person an idiot, he is saying the coding is idiotic.    He comes close sometimes depending on some peoples take on the matter but i dont think i recall him ever attacking a person.   
« Last Edit: 29 Aug 2023, 10:20:51 am by durangod »

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +8/-0
    • Grumpy Young Man
Re: Blocking browser context menu
« Reply #11 on: 29 Aug 2023, 10:39:22 am »
Oh my, please don’t catch Jason on a bad day then... Coothead is a pussy cat in comparison...

@GrumpyYoungMan   yes i know DS can be grainy at times.  But in all the many years i have known him online he has never attacked me. I am not saying that coothead did (i took what he said 100% wrong). I am just saying that DS has never done so.  DS usually says one of the follow in most cases:

1. There is no reason to do that and explains why
2. Ok if your going to go down this road till you fall off a cliff, then atleast code it correctly, and shows example.
3. Why are you hacking that code to pieces like that, that is not the right way to do that, i would do it this way.
4.  Variables for nothing and the use of rediculous tick marks around field names drives me crazy...
5. That is not "fill in the blanks" job, that is "fill in the blank" job.
6. What!  Are we still living in 2004 and using php 4 

DS may be like sandpaper sometimes be he is always about the code.   When i first saw his posts on the old coding forum i was alittle shocked because i was not used to those kinds of replies on a coding forum environment.  Back then he went by a different name, off hand i dont remember, but i think i know which one looking at the userlist.   But anyway as the years went by he got alittle bit more like 20 grit sandpaper than 120 grit of years past.   But it was always about the same thing.  Code, code structure, whos job it is for different tasks.  Even though some of those views may have changed over the years, he still talks about the code.   Even when he says "doing it that way is idiotic"  he is not calling the person an idiot, he is saying the coding is idiotic.    He comes close sometimes depending on some peoples take on the matter but i dont think i recall him ever attacking a person.   
100% and to be fair a spade is a spade, no matter how you try and dress it up not to be, so personally, I like his no nonsense approach.

I also don’t think CootHead would have meant for you to take his comment in as a personal attack, I have had a few interactions with him!
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Blocking browser context menu
« Reply #12 on: 29 Aug 2023, 04:10:54 pm »
i have had more than a few which is why i should have known that the comment was innocent and i was bring a d...head.  i am embarrassed by my reply to him and have removed it from my post.  But thankfully you have saved it in your quote.

i cant apologize enough, he has been such a great help and has been so kind.  If i could i would kick my own ass.   I wish it never had happened.

maybe i should join the circus since i am able to type with both feet in my mouth and my head up my ass.

It will never happen again!
« Last Edit: 29 Aug 2023, 04:22:16 pm by durangod »

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +8/-0
    • Grumpy Young Man
Re: Blocking browser context menu
« Reply #13 on: 29 Aug 2023, 06:28:25 pm »
i have had more than a few which is why i should have known that the comment was innocent and i was bring a d...head.  i am embarrassed by my reply to him and have removed it from my post.  But thankfully you have saved it in your quote.

i cant apologize enough, he has been such a great help and has been so kind.  If i could i would kick my own ass.   I wish it never had happened.

maybe i should join the circus since i am able to type with both feet in my mouth and my head up my ass.

It will never happen again!
Don’t beat yourself up over it, text on a screen is hard to gauge the tone…
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

Dave

  • Junior Member
  • *
  • Posts: 38
  • Karma: +12/-0
Re: Blocking browser context menu
« Reply #14 on: 6 Oct 2023, 12:11:20 pm »
If I've viewed your page, everything already resides in my browser cache :) It's always good to learn things and I applaud your efforts. I find it interesting that, after more than a decade, it still can't be done reliably across browsers. Not that I think it should mind you!
Dave

 

SMF spam blocked by CleanTalk

Advertisement