PC Review


Reply
Thread Tools Rate Thread

Disabling right click on web browser control

 
 
Robert
Guest
Posts: n/a
 
      24th May 2004
Can I programmatically disable the right click context menu?


 
Reply With Quote
 
 
 
 
Coleen
Guest
Posts: n/a
 
      24th May 2004
You can do it with JavaScript - here's a bit of JavaScript for how we did it...

<script language="JavaScript">
var ErrMsg = "Sorry! Right Click is disabled. Please use your browser menu options.";
function disableRightClick(btnClick)
{
if (navigator.appName == "Netscape" && btnClick.which == 3) // check for netscape and right click
{
alert(ErrMsg);
return false;
}
else if (navigator.appName =="Microsoft Internet Explorer" && event.button == 2) // for IE and Right Click
{
alert(ErrMsg);
return false;
}
}
document.onmousedown = disableRightClick;
</script>

This code also takes NetScape browsers into account.

Coleen

"Robert" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Can I programmatically disable the right click context menu?
>
>

 
Reply With Quote
 
Robert
Guest
Posts: n/a
 
      24th May 2004
I cannot modify the HTML itself. I have created a small browser application
but I cannot have the right-click menu show up. Can I define my own and then
disable it? Will that override the default one the control has?

"Coleen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
You can do it with JavaScript - here's a bit of JavaScript for how we did
it...

<script language="JavaScript">
var ErrMsg = "Sorry! Right Click is disabled. Please use your browser
menu options.";
function disableRightClick(btnClick)
{
if (navigator.appName == "Netscape" && btnClick.which == 3) // check for
netscape and right click
{
alert(ErrMsg);
return false;
}
else if (navigator.appName =="Microsoft Internet Explorer" && event.button
== 2) // for IE and Right Click
{
alert(ErrMsg);
return false;
}
}
document.onmousedown = disableRightClick;
</script>

This code also takes NetScape browsers into account.

Coleen

"Robert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can I programmatically disable the right click context menu?
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      24th May 2004
* "Robert" <(E-Mail Removed)> scripsit:
> Can I programmatically disable the right click context menu?


\\\
<body onContextMenu="return false">
///

in your HTML file. Maybe this can be done using the DOM too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Coleen
Guest
Posts: n/a
 
      24th May 2004
Sorry, I don't know of any way to do this except through the JavaScript. Is
there a reason you can't modify the HTML?

"Robert" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I cannot modify the HTML itself. I have created a small browser

application
> but I cannot have the right-click menu show up. Can I define my own and

then
> disable it? Will that override the default one the control has?
>
> "Coleen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> You can do it with JavaScript - here's a bit of JavaScript for how we did
> it...
>
> <script language="JavaScript">
> var ErrMsg = "Sorry! Right Click is disabled. Please use your browser
> menu options.";
> function disableRightClick(btnClick)
> {
> if (navigator.appName == "Netscape" && btnClick.which == 3) // check for
> netscape and right click
> {
> alert(ErrMsg);
> return false;
> }
> else if (navigator.appName =="Microsoft Internet Explorer" &&

event.button
> == 2) // for IE and Right Click
> {
> alert(ErrMsg);
> return false;
> }
> }
> document.onmousedown = disableRightClick;
> </script>
>
> This code also takes NetScape browsers into account.
>
> Coleen
>
> "Robert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Can I programmatically disable the right click context menu?
> >
> >

>
>



 
Reply With Quote
 
Charles Law
Guest
Posts: n/a
 
      24th May 2004
Hi Robert

Implement the IDocHostUIHandler interface and in the ShowContextMenu
function return an HRESULT of S_OK. This will prevent the context menu from
being displayed.

You can inform the WebBrowser control that you have implemented the
IDocHostUIHandler interface by getting an ICustomDoc interface from the
document, and calling SetUIHandler method with a reference to your class
that implements the interface.

HTH

Charles


"Robert" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I cannot modify the HTML itself. I have created a small browser

application
> but I cannot have the right-click menu show up. Can I define my own and

then
> disable it? Will that override the default one the control has?
>
> "Coleen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> You can do it with JavaScript - here's a bit of JavaScript for how we did
> it...
>
> <script language="JavaScript">
> var ErrMsg = "Sorry! Right Click is disabled. Please use your browser
> menu options.";
> function disableRightClick(btnClick)
> {
> if (navigator.appName == "Netscape" && btnClick.which == 3) // check for
> netscape and right click
> {
> alert(ErrMsg);
> return false;
> }
> else if (navigator.appName =="Microsoft Internet Explorer" &&

event.button
> == 2) // for IE and Right Click
> {
> alert(ErrMsg);
> return false;
> }
> }
> document.onmousedown = disableRightClick;
> </script>
>
> This code also takes NetScape browsers into account.
>
> Coleen
>
> "Robert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Can I programmatically disable the right click context menu?
> >
> >

>
>



 
Reply With Quote
 
Nicolas
Guest
Posts: n/a
 
      17th Jun 2004
Hello Charles,

>Hi Robert
>
>Implement the IDocHostUIHandler interface and in the >ShowContextMenu
>function return an HRESULT of S_OK. This will prevent the >context menu

from
>being displayed.
>
>You can inform the WebBrowser control that you have >implemented the
>IDocHostUIHandler interface by getting an ICustomDoc >interface from

the
>document, and calling SetUIHandler method with a >reference to your

class
>that implements the interface.
>
>HTH
>
>Charles


Do you know of a way / any documentation on using the IDocHostUIHandler
from VB6? I would like to pass user click events from the an HTML page
in the WebBroswer Control to my hosting VB app. Is this possible?


Cheers,
Nicolas
http://www20.brinkster.com/intefacesa/

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Charles Law
Guest
Posts: n/a
 
      17th Jun 2004
Hi Nicholas

Unfortunately I haven't used the WebBrowser control in VB6, so I am probably
not the best person to ask. You could try one of the dedicated VB
newsgroups: microsoft.public.vb.*etc*.

Perhaps someone else here can suggest a more specific group.

Charles


"Nicolas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Charles,
>
> >Hi Robert
> >
> >Implement the IDocHostUIHandler interface and in the >ShowContextMenu
> >function return an HRESULT of S_OK. This will prevent the >context menu

> from
> >being displayed.
> >
> >You can inform the WebBrowser control that you have >implemented the
> >IDocHostUIHandler interface by getting an ICustomDoc >interface from

> the
> >document, and calling SetUIHandler method with a >reference to your

> class
> >that implements the interface.
> >
> >HTH
> >
> >Charles

>
> Do you know of a way / any documentation on using the IDocHostUIHandler
> from VB6? I would like to pass user click events from the an HTML page
> in the WebBroswer Control to my hosting VB app. Is this possible?
>
>
> Cheers,
> Nicolas
> http://www20.brinkster.com/intefacesa/
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
click event with web browser control Rotsey Microsoft VB .NET 0 7th Sep 2007 02:04 PM
Adding a Click event to a Web Browser control Jayyde Microsoft C# .NET 7 31st Oct 2006 05:09 PM
Disabling click and right-click on the Picture I inserted in an Excel document shettyna@yahoo.com Microsoft Excel Worksheet Functions 1 2nd Jun 2006 09:13 PM
Making a web browser control react to a key click. UJ Microsoft C# .NET 0 6th Jan 2006 06:21 PM
Trapping right-click on web browser control. Hadi Microsoft Dot NET 1 4th Mar 2004 05:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:34 PM.